The Serbian somehow stayed alive in the second set, breaking when Murray was serving for the match and then winning a remarkable tie-break 13-11.
And the world number two broke the Scot's resolve in the decider to claim a 5-7 7-6 (13/11) 6-3 victory in three hours 21 minutes.
It was two-time defending champion Murray's first defeat in Shanghai in 13 matches.
Murray, who beat Djokovic in an epic five-set match to lift the US Open crown last month, came into the final in fine form, having dismantled world number one Roger Federer in yesterday's [Saturday] semi-final.
And, despite going a break down early on, he recovered well to win a first set which featured seven breaks of serve.
The crucial break came when he moved 6-5 in front, his opponent responding with a huge display of frustration, smashing his racket on the ground.
Murray duly closed out the set.
And a straight-sets victory looked on the cards when he served for the match at 5-4, his the only break this time.
But from 0-30 down and having saved a championship point, the Serbian upped his game and broke back before forcing the tie-break which would change the course of the match.
Murray fell 3-1 behind in the breaker before getting back on terms and carving out two more match points at 6-4.
But Djokovic saved both and then two more at 8-7 and 10-9 before finally levelling the match on his fourth set point.
The momentum was now firmly with the five-time Grand Slam winner and be broke in the decider for a 4-3 lead.
Serving to stay in the match at 3-5, Murray saved two championship points, but could not do so a third time as Djokovic ended the Scot's winning run in Shanghai.