In another entertaining matchup between the two U.S. Open finalists, Djokovic seemed headed for defeat when Murray was serving for the match at 5-4 in the second set.
But the second-ranked Serb saved one match point in that game before breaking back for 5-5. He then saved four more in a tense tiebreaker and carried his momentum into the deciding set, breaking the Briton twice to earn his fifth title of the year.
"I won the match. But, you know, as spectators could see, we were very close," Djokovic said. "It was a very even match throughout the whole three sets. He was so close to the victory that I cannot say I was the better player."
It was Murray's first loss in Shanghai in 13 matches.
Murray, who beat Djokovic in five sets at Flushing Meadows for his first Grand Slam title, saved two match points in the final game, but sent a backhand long on the third.
"It was a disappointing one to lose," Murray said. "I've lost tougher matches than that before in the biggest events. So I'm sure I'll recover from it pretty well.
"It's not like I threw the match away. I didn't make, I don't think, any real glaring errors or anything."
In a matchup of two of the game's best returners, both players struggled to hold serve early, trading breaks three times, and were tied 4-4 in the first set.
When Djokovic was broken for the fourth time in the 11th game, he lost his cool and shattered his racket by smashing it into the ground four times before slinging it disgustedly toward his sideline chair.
"We are professional tennis players and we're big rivals, but in the end we're humans. We shouldn't be ashamed of our emotions," Djokovic said. "I don't see anything bad in showing your emotions -- positive, negative emotions. We can't just be flat-faced throughout the whole match."
The momentum seemed to shift with one audacious shot from the Serb, just as Murray appeared to be closing in on his third straight title at the tournament.
Trailing 5-4 and 30-0 in the second set, Djokovic chased down a lob from Murray and hit a perfect between-the-legs shot, then followed it up with a drop shot to win the point. He went on to save Murray's first match point with a forehand and broke back when the Briton missed a forehand of his own two points later.
In the 20-minute tiebreaker, Djokovic finally prevailed when he converted his fourth set point with a forehand winner.
Murray couldn't recover, and Djokovic broke for a 4-3 lead before winning the next two games to wrap up the win.
Djokovic also beat Murray in five sets in the Australian Open semifinals this year and improved his record against the Briton to 9-7.
"We had an incredible year so far with our matches, big matches in important events," Djokovic said. "He definitely is a different player this year. You could see by the results he's achieved. He's more aggressive on the court and he's definitely a danger to anybody on any surface."