"We discovered this two hours ago. I have to stop," the former Giro d'Italia winner, 37, told a shocked news conference on Monday.
Basso was set to be one of Alberto Contador's key lieutenants in the mountains over the next two weeks.
He caught his groin in a crash on stage five and the cancer was discovered in a check-up on the race's first rest day.
Tinkoff-Saxo team-mate Contador was in tears as he sat next to Basso during his announcement.
Basso, who will travel to Italy to undergo surgery as soon as possible, twice finished on the podium during Lance Armstrong's long reign at the Tour and many, including Armstrong, expected him to follow the American on to the top step when he retired in 2005.
But Basso got caught up in the Spanish Operation Puerto doping scandal and eventually admitted to the intention to cheat. He was given a two-year ban in 2007.
The Italian climber, who owns a blueberry farm in Lombardy, has claimed five top-10 finishes in Grand Tours since his return to the sport, including a Giro win in 2010.
He is also one of the friendliest and more relaxed members of the professional peloton so this news will be greeted with considerable dismay.
His diagnosis will also increase the focus on Armstrong's arrival in France next week to ride two stages of the Tour with ex-England footballer Geoff Thomas - a day ahead of the race - to raise money for a cancer charity.
Armstrong recovered from life-threatening testicular cancer earlier in his career to win the seven Tour titles he was eventually stripped of for his doping activities.
Armstrong tweeted on Monday that he wished Basso "the very best".
Italian rider Ivan Basso has withdrawn from the Tour de France after revealing he has testicular cancer.