The players were only separated by a fifth set tie-break when the scores reached 12-12.
Victory for the No.1 seed brought him his fifth Wimbledon singles title, moving him level with Bjorn Borg in the all-time list. He had previously beaten Federer in 2014 and 2015.
Djokovic won 7-6(5), 1-6, 7-6(4), 4-6, 12-12(3) in four hours and 55 minutes.
It was a match of high quality which will be remembered principally for an astonishing final set lasting almost two hours.