The 26-year-old won gold for Spain in Beijing four years ago but will not be defending his crown this summer.
Nadal also confirmed he will not be travelling to London for the Games, which would have been his first event since being eliminated in the second round at Wimbledon by then 100th-ranked Lukas Rosol.
"I am not able to compete at the Olympics in London and therefore will not be traveling as planned with the Spanish delegation," he said in a statement on the Spanish federation (RFET) website, www.rfet.es.
"I have to think about my colleagues. I cannot be selfish and I have to think of the good of Spanish sport, especially Spanish tennis, and let a team-mate who is better prepared to compete.
"I've waited until the final moment of my preparation and my training, but I cannot do it."
Nadal was due to carry the Spanish flag at the Olympic ceremony in eight days.
The Spaniard added: "It is one of the saddest days of my career.
"Perhaps one of the most special moments was to be Spain's flagbearer in the opening ceremony for the Games in London, so you can imagine how difficult it has been making this decision. "
RFET president Jose Luis Escanuela was also devastated, saying: "It's the worst news we could have.
"Rafa has always been an example of perseverance and tenacity, which makes it hard to miss out because surely would have loved to return to the Games. I hope he recovers quickly."
Watch: Nadal withdraws from London 2012.. More Videos
Earlier this week Nadal had said he hoped to be fit enough to lead the Spanish team at the opening ceremony as he continued his recovery from a knee complaint.
Speaking as he received the flag from the Spanish Olympic Committee, he said: "I am doing everything possible to recover. After Roland Garros I had a difficult time, but the excitement is at its maximum, I am working as hard as I can and hopefully I will be at 100%.
"I am the one who is most worried. I hope that things improve and my intention is to arrive in London well prepared and recuperated. It is for this that I work every day.
"Carrying the flag will be something unforgettable and I hope that Spain continue on the path of success it has been on for the past few years."
With Nadal pulling out of the Games, however, the RFET have until midnight tonight to name his replacement for the doubles.
The Spanish federation have already confirmed that the reigning gold medallist would be replaced in the men's singles by Feliciano Lopez.
Nadal won the last of 11 grand slams earlier this year at Roland Garros and was considered amongst the favourites for success at the Olympics.
The news has seen odds shorten on the likes of Novak Djokovic and Roger Federer, while Great Britain's Andy Murray will also be hoping to triumph this summer.