Djokovic, the defending champion won 7-6, 2-6, 7-6, 1-6, 13-12 on Sunday (Monday morning NZ time).
It was an epic encounter between two of the greatest tennis players of all-times.
The scene was set for a cliffhanger with a tiebreaker in the first set, won 7-6 by Djokovic.
Federer, 37, fought back imperiously to take the second set, 6-2.
But Djokovic, 32, prevailed 7-6 in the third after another tiebreaker.
Federer broke the Serb's serve in the fourth to win 6-4 and take the tussle to a fifth set decider.