So, so close.

Andy Murray's hopes of a third straight Shanghai Masters title were dashed yesterday by a never-say-die performance from Novak Djokovic, who edged out the Scot in a match of breathtaking standard and drama.

There is no shame in losing to Djokovic, who gained a small measure of revenge for his defeat by Murray in the US Open final last month, but Murray will be kicking himself that he was unable to take one of five match points as he went down 5-7, 7-6, 6-3 to the world No.2.

"It's not like I threw the match away," said a clearly disappointed Murray. "I didn't make any real glaring errors or anything. When I had my chances, he just served very well and hit a couple of lines when he needed to. One of his forehands hit the outside of the line."

Only one of the match points could be described as a missed opportunity as Murray dropped a backhand short and was punished. On the other four, Djokovic showed the attitude that has won him so many titles as he saved them by going for broke.

"It was a disappointing one to lose," Murray said. "[But] I've lost tougher matches than that before in the biggest events. So I'm sure I'll recover from it pretty well."

Djokovic admitted that it could have gone either way. "I can't say I was the dominant player – he had all those match points," said the Serb, who is now almost certain to overtake Roger Federer to become world No.1 before the year is out. "But I just kept trying and in the end maybe he was a little more tired, but it was a great match."

Every time these two men meet, the extraordinary is dished up in a series of incredible rallies, both going toe to toe, power against power, defence against defence, mind against mind. Neither man could settle on their own serve, so brilliant were the other's returns. Murray, who had overpowered Federer in the semi-finals, thumped one forehand return at a whopping 167 kmph that left Djokovic standing exactly where he had landed.

After recovering an early break, Murray had the upper hand in the first set, his backhand brilliant and his forehand, the revelation of 2012, dominating the points whenever Djokovic did not put the ball within inches of the baseline. At 5-5, Murray earned the vital break when Djokovic missed a forehand volley and the Serb smashed his racket before flinging it towards his bag in disgust.

Murray closed out the set and then in the second set, at 3-3, he produced a brilliant return and passing shot to break again. After both men held to make it 5-4, Murray stood to serve out for the match. And then the fun began. The Scot looked to have it in the bag when he led 30-0 and as he watched a fine lob sail over Djokovic's head but the Serb retrieved it with a spectacular between-the-legs shot and then topped it all off by hitting a drop shot for the winner.

That galvanised Djokovic and he broke back for 5-5. The tiebreak was a classic. Murray led 6-4 and held three more match points only for the world No.2 to save them all with a breathtaking display of courageous, all-out tennis. Murray's racket was then smashed to smithereens as Djokovic took it 13-11 and then, with his tail up and with the Scot tiring, he broke for 4-3 in the decider. Two games later, he clinched victory on his third match point after three hours, 21 minutes of the most stunning tennis.

It was the second week in a row that Murray had lost from match point up, poignant given he had been talking up his ability to finish off matches under pressure.

Murray is due to play in Basle next week before the Paris Masters but may yet decide to drop one of the tournaments in a bid to stay fresh for the season-ending Barclays ATP World Tour Finals.