Melzer is on the verge of breaking into the world's top 10
Rafael Nadal suffered a shock defeat in the third round of the Shanghai Masters as an inspired Juergen Melzer beat the world number one 6-1 3-6 6-3.
The Spaniard recovered from an opening-set blitz to level the match but the Austrian held his nerve in the decider.
Melzer served out to love to inflict the world number one's first defeat before the last-eight stage all year.
Roger Federer made the quarter-finals with a 6-3 6-4 win over a battling Andreas Seppi of Italy.
Melzer could have sealed his surprise win sooner but saw Nadal save three match points, the first on a dubious line call, at 2-5 on his serve.
It was also the first time Nadal had conceded even a set to Melzer after three previous meetings with his fellow left-hander.
"I was always strong on the key points, and I am very proud I served it out, especially as I had already won the match at 5-2 and got a bad call," said Melzer, who reached this year's French Open semi-finals.
"All of a sudden it was 5-3 but it helps you to relax when you step up on the first point and hit a back-hand winner down the line.
"Once you reach the semi-finals of a Grand Slam everything is possible, and today was a great moment."
The world number 12 will play Argentine Juan Monaco, an easy 6-0 6-2 winner over German Mischa Zverev, in the last eight.
Nadal, who has won seven titles including three Grand Slams in 2010, admitted that the effects of his successful season may be catching up on him.
"I felt slow on court, I had more mistakes than usual," he said.
"I played shorter than usual. I was a little bit more tired just physically and mentally."
Federer, playing his first tournament since the US Open in September, had to work hard to stifle a buoyant Seppi.
Federer was stretched at times by Italy's Seppi
The Swiss made the solitary break of the opening set in the fourth game, but was taken to deuce in his subsequent two service games as the world number 58 attempted to counter.
Seppi, 26, defended four break points in the early stages of the second, before edging ahead with a break of his own.
But Federer immediately responded in kind and, as Seppi appeared to struggle with a stomach complaint, ratcheted up the intensity to take the final two games.
"The points were tough we were both feeling it there for a while, but I was happy to come back. It was a good match in the end," said Federer.
Novak Djokovic enjoyed the swiftest passage into the quarter-finals of any of the top four seeds with a comfortable 6-1 6-1 victory over Richard Gasquet.
Frenchman Gasquet appeared to have little left a day after winning two matches due to the rain-delayed schedule earlier in the week and dropped serve five times.
"I did really well from the start. I put pressure on him. I was aggressive and I knew I had to be," said Djokovic.
The second seed, will play Spaniard Guillermo Garcia-Lopez, who upset Wimbledon finalist Tomas Berdych 7-6 6-3, in the last eight.
Robin Soderling, the number five seed, also came through in straight sets, 7-5 6-4 against Spaniard David Ferrer.
The Swede will play Federer, who he beat in the quarter-finals of this year's French Open, next.