"Unfortunately I have a bad announcement to give to you guys," the 37-year-old Italian told a news conference on the first rest day of this year's Tour.
"I crashed in the fifth stage and I felt pain in my left testicle and yesterday we spoke with the doctor of the Tour de France and we decided to do some analysis to the hospital and the examination gave me bad news," said Basso, who was addressing the media ahead of his Tinkoff-Saxo team leader Alberto Contador.
"I have a small cancer in the left testicle so it's easy to understand I have to stop and go back to Italy."
Basso will undergo surgery in Milan today.
Contador, who is attempting a rare Giro/Tour de France double, would not discuss the race, in which he sits fifth overall, 1min 03sec behind leader Chris Froome (Sky).
"I have grown closer to Ivan in the past weeks and this is terrible news," said Contador, with tears in his eyes.
"On behalf of the entire team I'd like to say that it has been a blow to all of us. We never imagined such a thing would happen. Ivan's health is the absolute priority and he has to undergo all the necessary tests to find the best solution. I'd like to stress that the entire team will give its best in order to get the yellow jersey and enjoy it in Paris with him.
"During the 120 days that Ivan and I spent together, over the last 180 days, I was able to see what a great champion he is. I'm sure he will overcome this and we will see him in two weeks in Paris."
Steven de Jongh, Tinkoff-Saxo's sport director, said via a statement: "As everybody understands, today is not a day to speak about the Tour de France, the days ahead or Alberto's main rivals on the mountain stages.
"All that is irrelevant and we are all here solely to support Ivan. The entire team hopes to meet him again in Paris and hand him the yellow jersey."
Basso looked on course for Tour glory when he won the white jersey for the best young rider in 2002, in an era dominated by the disgraced Lance Armstrong, a testicular cancer survivor himself.
He never won the world's greatest race, however, finishing third and second overall in 2004 and 2005 respectively.
Basso won the Giro twice, his only grand tour titles, thanks to impressive climbing performances.
His career, however, was tainted by a two-year ban for his implication in the Operation Puerto blood-doping scandal.
Basso admitted to "attempted doping" in 2007 and was hit by a backdated suspension.
He won the Giro less than two years after his comeback from suspension, but only managed seventh in the 2007 Tour. He was one of Contador's lieutenants on this year's Tour, having helped the Spaniard win the Giro last month.