A set down, he produced two sets of high-quality tennis to secure a 4-6, 6-3, 6-3 win in two hours, 19 minutes.
Serena Williams earlier won the women's title in a final ruined by injury to her opponent Sara Errani.
Nadal drew first blood in the men's final when he broke in game three and, after consolidating his advantage, he extended it to 4-1 in Djokovic's next service game.
The Serb responded by smashing his racquet and although he got the first break back in the next game, Nadal was still serving for the set at 5-4 - and it was a game he took.
Djokovic broke at the first time of asking in the second set, taking the game with a cross-court forehand. And although he was sloppily broken back while serving at 3-1 up, the world No.2 produced an otherwise faultless set which he won 6-3 to force a decider.
He continued his momentum with an early break but Nadal recovered to level at 3-3, with both players stepping up in quality. It was Djokovic, though, who found an extra gear as he broke again to lead 4-3 and then turned the screw, his third break of the set and sixth of the match securing victory.
Djokovic hit 46 winners to Nadal's 15 and won 72% of points on his first serve opposed to 54 for the Spaniard.
It was Djokovic's 19th ATP Masters title and his fifth in the last six such events. Djokovic, speaking in Italian at the on-court presentation, said: "It's a special moment to win. I want to thank my team who are always close to me and give me tons of support throughout my career. None of this would be possible without them."
Earlier, Errani had recovered from a break down to bring the first set back on serve against Williams but required lengthy off-court treatment on her left hip and thigh.
Upon the resumption, Williams won seven straight games to comfortably seal the title 6-3, 6-0 after 72 minutes of play.