Left-hander Melzer continued to strike the ball heavily, especially off the forehand side, and Murray grew visibly rattled at his inability to polish off his opponent.
Eventually the Scot got the break in the seventh game of the second set but he failed to claim victory when serving at 5-4 as the 26-year-old Melzer forced a break of his own.
When the 29-year-old Murray served for the match for the second time he made no mistake, wrapping up victory when Melzer sent a backhand return wide.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
Murray, who looked drained at the end, will play Spain's Nicolas Almagro next.
"He played great, great tennis and dominated large parts of the match," Murray said on court after warmly congratulating his opponent. "I told him at the net he will keep climbing the rankings if he plays tennis like that."
"I played pretty good but he was hitting the ball huge."
Djokovic, seeded two, had an easier time against Argentina's Horacio Zeballos, winning 6-3 6-4 in 72 minutes.
The Serb will face 38-year-old Czech Radek Stepanek who became the oldest ATP Tour quarter-finalist since Jimmy Connors, aged 42, in 1995, when he beat wildcard Arthur De Greef.
(Reporting by Martyn Herman, editing by Neil Robinson)
