Nadal won the French Open for a record seventh time this year but has struggled with left knee problems at times during the season. Shortly after winning his 11th Grand Slam title at Roland Garros, he lost to 100th-ranked Lukas Rosol in the second round at Wimbledon.
Nadal has not played since.
The third-ranked Nadal said Thursday he wasn't in condition to compete at the Olympic tennis tournament — which also will be held at Wimbledon.
"This is one of the saddest moments of my career," Nadal said in a statement. "I have to think about my companions, I can't be selfish and I have to think of what's best for Spanish sport, especially tennis and Spanish players, and give fellow sportsmen with better preparation the chance to compete.
"I tried to hurry my preparations and training to the very last minute, but it was not to be."
The 26-year-old Spaniard has won two Wimbledon titles and claimed gold at the 2008 Beijing Olympics.
"You can imagine how difficult it was to take this decision," he said.
Nadal had been the last of the four singles finalists from 2008 in the London Olympics. Men's silver medal winner Fernando Gonzalez of Chile, who Nadal beat in straight sets in Beijing, and women's finalists Elena Dementieva and Dinara Safina of Russia, will also be missing from the London Games.
Nadal did not mention a specific injury in his statement but he cancelled a charity match in Madrid on July 4 because of tendon problems in his left knee. He has had recurring knee problems in the past.
"I am not in condition to compete in the London Olympics and therefore will not travel as planned with the Spanish delegation to take part in the games," Nadal said. "(This) is one of the saddest days of my career as one of my biggest ambitions, that of being Spain's flag bearer in the opening ceremony of the games in London, cannot be."
It wasn't immediately known who would replace Nadal on Spain's tennis team or who would carry the flag at the opening ceremony in his place.
Nadal's absence leaves top-ranked Roger Federer of Switzerland and No. 2 Novak Djokovic of Serbia as the favourites, although Wimbledon runner-up Andy Murray of Britain will again likely have a wave of home support as he tries to reach the final at the All England Club for the second time in less than a month.
Murray lost to Federer in the Wimbledon final on July 8. The tennis gold medal match at the Olympics will take place on the same Centre Court on Aug. 5.
Both the men's and women's doubles champions are set to defend their Olympic titles in London, however. Federer and Switzerland teammate Stanislas Wawrinka are the men's defending champions, while American sisters Venus and Serena Williams won gold in the women's doubles in Beijing.
AP Sports Writer Gerald Imray in London contributed to this report.