Andy Murray failed in his bid to win his third consecutive Shanghai Masters after losing to Novak Djokovic in a thrilling encounter. 

It was a meeting that was as heated and astounding as their epic US Open final, with Djokovic coming out on top this time, triumphing 5-7 7-6 (13-11) 6-3.

In a memorable encounter, the British world number three showed plenty of the form he so brilliantly displayed against Swiss legend Roger Federer during Saturday's semi-finals. But Djokovic - who had failed to beat Murray in their last two matches - provided a much sterner test. 

Murray edged the first set, with the Scot breaking Djokovic four times. The world number two reacted to Murray's domination of the match rather petulantly, smashing his racket in utter frustration. 

Djokovic then composed himself during a dramatic second set, with the Serb heroically saving five match points, before taking the tie-break and breaking Murray twice in the third.

With the momentum firmly in his favour, Djokovic broke twice again to go 5-3 up in the decider, as Murray struggled to find his range. And it was a long backhand, a shot synonymous with Murray's game, which ended his winning streak in Shanghai. 

Djokovic, who won his fifth title of the year, said, "it was a thrilling match [and] very long. Three and a half hours for best of three is quite long. But I have got used to it."

"Whenever I play Andy, I know it's going to be a gruelling fight with a lot of long rallies. It could have gone either way.

"I could not say I dominated the match because all three sets were very close and he had some match points. I could have easily been a runner-up today but I'm very proud of my fight."

Murray showed his obvious disappointment, but paid tribute to his friend.

"I've lost tougher matches than that before and I'm sure I will recover," he said. "But it was a top-quality match. Both of us played some unbelievable tennis at times.

"It was literally the difference of one, two centimetres [between] winning the match and losing it. You have to put things into perspective. It was obviously a bit frustrating but it was so close and could have been a different outcome.

"The third set, he played better than me. When I had my chances he served very well and hit the lines when he needed to.

"Most of our games have been tight, close matches but I feel like my game is there."