"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".

Bedene, 27, forced eight break points in the match, converting three to beat the world number 77 in 65 minutes.
The event is Bedene's first grass-court outing after a good clay campaign took him from 94th to 52nd in the world.
He will play either fourth seed Gilles Muller or Italy's Andreas Seppi next.
British and world number one Andy Murray will start his grass-court campaign at the Aegon Championships at Queen's Club next week alongside national number two Kyle Edmund.
Davis Cup team-mate Dan Evans withdrew from the Nottingham Open on Monday with injury and is having treatment before the start of Wimbledon on 3 July.

Roman Seleznev, 32, was found guilty by a federal jury in Seattle on 38 of 40 counts, including intentional damage to a protected computer and wire fraud.
Prosecutors said he was a "master hacker" behind a plan which led to $170m (£131m) of fraudulent purchases.
Vowing to appeal, his lawyer argued he had been kidnapped by US agents.
Seleznev (his name is also spelt Seleznyov in English) faces a mandatory minimum sentence of four years in jail, lawyer John Henry Browne said. A sentence is expected on 2 December.
The Russian also faces similar charges in federal courts in Nevada and Georgia.
Prosecutors say Seleznev hacked into retail systems and installed malware to steal credit card numbers from businesses, mostly pizza restaurants in the state of Washington.
He then sold the information online, they say. The scheme is said to have been carried out between 2008 and 2014.
Roman is the son of Valery Seleznev, a Russian member of parliament for the Liberal Democratic Party.
He and his girlfriend were arrested by US Secret Service agents at a Maldives airport in July 2014.
Lawyers argued that his arrest was a "kidnapping" or an "illegal rendition" that violated international law but a US district judge blocked that argument from the trial.
Mr Browne said they planned to challenge his client's arrest and a ruling that allowed prosecutors to introduce evidence from a corrupted laptop seized with him.
The computer contained more than 1.7m stolen numbers, along with evidence linking him to various servers, prosecutors said.
Italian rider Ivan Basso has withdrawn from the Tour de France after revealing he has testicular cancer.
[NEXT_CONCEPT]
British number four Aljaz Bedene made the quarter-finals of the Ricoh Open tournament in the Netherlands with a comfortable 6-3 6-4 win over the United States' Ernesto Escobedo.
[NEXT_CONCEPT]
The son of a Russian MP has been convicted on charges that he orchestrated a hacking scheme that targeted US pizza restaurants.