Nadal was stunned by Czech Lukas Rosol in the second round of Wimbledon last week, and was due to play an exhibition game against world number one Djokovic at Real's ground on July 14.
"I wish to apologise to all, especially the supporters who had already purchased tickets for this good cause," said Nadal, who won gold at the Beijing Olympics, in a statement on the Real Madrid website.
"Doctors have been examining my knee and say I suffer from tendonitis on the patellar ligament and that I must rest for 15 days, which prevents me from playing against Novak Djokovic as planned and announced.
"I saw the doctors on Monday and began the recovery process to be fit to represent Spain in the London Olympics. We will try to look for a new date for the event.
"I will now combine my recovery with short holidays before returning to training in 15 days. Once again, thanks to all."
The event, organised by the Real Madrid and Rafa Nadal Foundations, had hoped to set a record attendance for a tennis match.
Nadal and Djokovic will carry Spain and Serbia's flags at the Olympic opening ceremony in London on July 27.