Federer, who was vying for a record-extending ninth Wimbledon title, had opportunities to take the first set having led 5-3 in the tiebreak and also the third when he held a set point.
But the Serb ground out the win to secure his 16th grand slam, two shy of Rafael Nadal and four behind Federer.
“This was mentally the most demanding [win of my career] because of the circumstances and Roger across the net was playing well,” Djokovic told CNN.
“He was match points up and serving and in those moments you just try and stay there, try to stay present and find that strength and self-belief and in the end I managed to pull it out.
“I’m very, very, very happy and proud of the achievement today … And exhausted as well, of course.”
Federer won 14 more points than Djokovic over the course of the encounter, hitting 40 more winners in the process.
It very much felt like one that got away for the Swiss, who confessed afterwards that it felt like “an incredible opportunity missed.”
World No. 1 Djokovic has now won four of the past five men’s grand slam singles titles, a run only interrupted by Nadal’s victory at the French Open.