After four hours and 15 minutes of intense battle on Suzanne Lenglen Court, No 22 seed Melzer eventually triumphed 3-6, 2-6, 6-2, 7-6 (7-3), 6-4 as Djokovic, who has claimed to be suffering from hayfever-like symptoms, failed to keep up with the pace. Even so, he did not go down easily.
After narrowly missing his chance to win the match in the fourth set, Djokovic was up 3-2 in the fifth as it went to serve in the early stages. Djokovic then had the chance to break Melzer and take a potentially decisive lead, but Melzer hit an outstanding drop shot to save the point. Djokovic went 4-3 up, but Melzer smashed an ace to tie it once again.
The Austrian then stole the initiative with a forehand down the line that made it 30-0 but, as he has done all tournament, he failed twice on break point before eventually taking his third opportunity as Djokovic's volley hit the net.
Melzer got to match point only to dump a routine volley into the net and allow Djokovic to take it to deuce. A tense battle followed, but Melzer won on his third match point as Djokovic's return went long.
Djokovic refused to blame umpire Carlos Bernardes for his defeat but hit out at the crucial call that could have saved his skin. The third seed had struggled to contain his fury when a line call went against him while Melzer was serving for the match at 5-4, 0-15 in the deciding set.
The Serbian was adamant his shot had clipped the line, and although Bernardes came down to check the mark on the clay, the umpire was equally convinced the ball was out.
Djokovic, who went on to save two match points before Melzer finally sealed victory, was still smarting about the call long after the match had finished.
"For somebody who is a chair umpire of so many years and years experience to make such a mistake at that point is unbelievable," he said. "I don't know what was going on with him, but the ball looked good from everywhere. Even on the TV, you could see it was good. I can't blame him for losing this match, of course. That's one call.
"If that call went in my favour, maybe I would break him.
"That game would be 0-30 and he would feel a little pressure. But I should have done my job earlier. That's definitely my fault, and I paid the consequences."
The 29-year-old Melzer is through to his first ever Grand Slam semi-final, although a meeting with Nadal may be viewed by some as a dubious prize.
Nadal shook off dogged resistance from Nicolas Almagro to stay on course for a fifth French Open title.
Although he maintained his record of not having dropped a set at this year's tournament, the world No 2 was made to fight all the way by his fellow Spaniard before sealing a 7-6 (7-2), 7-6 (7-3) 6-4 victory in two hours and 35 minutes.
Almagro atoned for his humiliation by Nadal at the same stage at Roland Garros two years ago with a courageous show of defiance. But he was unable to compete in the tie-breaks against an opponent who is now the overwhelming favourite for the title following defending champion Roger Federer's demise on Tuesday night.
Nadal, who turns 24 today, had won all six of his previous meetings with Almagro, including a 6-1, 6-1, 6-1 thrashing at the same stage of the 2008 French Open – the most one-sided men's quarter-final in the tournament's history.
Almagro, who was bidding to reach his first grand slam semi-final, had taken a set from his compatriot in their past two meetings, but
Nadal was not to be denied, setting up his semi-final against Melzer.
Nadal will depose Federer as world No 1 if he goes on to win the title. "I'm not thinking about it," he said.
"My objective is to make it to the final, and then if I come out number one, fine."