"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," the third-ranked Spaniard said in a statement.
Nadal did not mention any specific injury, but he canceled 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.
Nadal has not played since losing in the second round of Wimbledon to then 100th-ranked Lukas Rosol, one of the most surprising results in the tournament's history.
"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," he said. "I tried to hurry my preparations and training to the very last minute, but it was not to be."
"(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," Nadal said. "You can imagine how difficult it was to take this decision."