It was the Serbian who took control of the opening set when he moved into a 2-0 lead on serve, but Murray answered straight back with a break and hold to level it at 2-2.
Both players remarkably lost their next two serves as the set was tied at 4-4, while it was Murray who broke at 5-5 to serve for a one-set lead.
The second set remained on serve until 3-3 when Murray broke and then held to move 5-3 ahead, but the Serbian broke back at 5-4 before the set was levelled at 5-5.
Both players held their serve as the match entered a mammoth tie-break in the second set and it was Djokovic who secured it 13-11 to take the match into a deciding set.
Each player demonstrated some of their finest tennis of the year in the early stages of the third, but it remained on serve until 3-3 when Djokovic broke to take a 4-3 lead.
The Serbian then held his serve in impressive fashion to move 3-5 ahead and he secured the victory with a final break to secure the third set 6-3.
Murray had been the defending champion in Shanghai.