Djokovic flew out of the blocks and took the first set 6-2, but after that Wawrinka battled back to take a 2-1 lead after the third.
When Djokovic won the fourth he was looking strong, but once more the Swiss player responded and managed the crucial break to claim the final set 9-7.
Read how the action unfolded with our live text commentary.
"It was really tough, but this year I cam back and was playing really well. He's an amazing champion and never gave up but I'm really, really, really happy.
"It was hard to believe I could do it in five sets. But I was feeling great on the court and had to remember not to give up and in the end I managed it.
"I was playing my best game, and when Novak is at his best he is better than me for sure. I tried to be aggressive and stick to my game and it worked."