On a Centre Court, with an atmosphere that felt at times more akin to football than tennis, Djokovic won 7-6 (7-5) 1-6 7-6 (7-4) 4-6 13-12 (7-3).
As the clock ticked to four hours 57 minutes, Federer hit a ball high to hand the Serb victory.
The world number one has won 16 Grand Slams – and four of the last five.
“It’s quite unreal,” Djokovic said after winning his fifth Wimbledon title.
Federer, who at 37 was chasing a record-equalling ninth Wimbledon singles title, added: “It was a great match, it was long, it had everything. Novak, congratulations, man, that was crazy.”
A meeting of the greats serves up a classic
A highly anticipated final between two of the sport’s greats always had the potential to go the distance – and this did that and more.
With fans unable to watch at times, while leaping to their feet and chanting at others, a nerve-jangling final set turned this into a classic.
When Federer had two championship points at 8-7, Djokovic held his nerve to save both and then break back, eventually taking it to the new tie-break at 12-12.
The Serb – who for extended periods of the match had been second best – had won the match’s previous two tie-breaks and he did so again, snatching victory when Federer scooped a return high.
The Swiss had been seeking to become the oldest Grand Slam champion of the Open era but instead found himself part of a different record as the match time surpassed Wimbledon’s longest final – the four hours 48 minutes of play in 2008 as he lost to Rafael Nadal.
“Like similar to ’08 maybe, I will look back at it and think, ‘well, it’s not that bad after all’. For now it hurts, and it should, like every loss does here at Wimbledon,” Federer said.
“Epic ending, so close, so many moments. Yeah, I mean, sure there’s similarities [between this and 2008]. I’m the loser both times, so that’s the only similarity I see.”
The incredible fifth set lasted more than two hours – you could have fitted in two of Saturday’s women’s singles finals in the time of that set alone.
Down in the stats – but up in the match
Anyone looking only at the stats for this match would simply not fathom how Djokovic came out on top.
The Serb trailed the Swiss on first-serve points won, winners made, aces, break points converted, games won and total points won and led him on double faults.
But he won the key points – and none more so than in the final set.
A diving volley winner at 5-5 and 15-30 prevented Federer establishing two break points, while having let the Swiss take an 8-7 lead with an opportunity to serve for the match, he immediately broke back.
Ignoring the increasingly vocal “Roger, Roger” chants from the partisan crowd and the cheers for some of the top seed’s double faults, Djokovic surged 6-3 ahead in the tie-break.
There was more drama when the final point had to be replayed after a Hawk-Eye challenge, but Djokovic finally celebrated victory – albeit in muted fashion – when Federer sent a forehand off the frame of his racquet.
There was no wild jumping up and down, just a smile to himself as he walked to the net to shake hands with Federer after becoming the first man to win a Wimbledon singles final having been down match point since 1948 when Bob Falkenburg saved three match points and came back to beat John Bromwich.
An emotional Federer looked over towards his wife and children in his box during the trophy presentation, perhaps an acknowledgement that less than four weeks from his 38th birthday his opportunities for more Grand Slams may be limited.
While the match will be remembered by many for its thrills, Federer said: “I will try to forget. I had my chances, so did he. We played some great tennis.”
How the drama unfolded in fifth set
3hrs 25mins – A Djokovic backhand winner secures a break of serve for 4-2 lead
3hrs 31mins – Federer breaks straight back when Djokovic nets forehand
4hrs 7mins – Federer goes a break up at 8-7 with a forehand winner
4hrs 10mins – An ace brings up two championship points for Federer
4hrs 12mins – Djokovic saves both match points, then breaks back to level match
4hrs 39mins – Successful Federer Hawk-Eye challenge brings up break point, but Djokovic fends it off to lead 12-11
4hrs 47mins – Code violation for Djokovic for swinging his racquet towards umpire’s chair
4hrs 48mins – First 12-12 final-set tie-break in Wimbledon singles begins
4hrs 55mins – Djokovic forehand brings up three championship points
4hrs 56mins – More drama as Djokovic successfully challenges a ball called out and point is replayed
4hrs 57mins – Federer skies a return and Djokovic wins his fifth Wimbledon title
BBC Sport tennis commentator Andrew Castle: “What a treat this has been. The top seed triumphs and it can surprise no one. Novak Djokovic has beaten Roger Federer in the longest final in Wimbledon history. And he’s beaten Roger Federer in all three Wimbledon finals that he has played him in. Roger Federer can look back with such pride on his effort.”
Former British number one Tim Henman on BBC TV: “I am still in a slight daze on Roger Federer’s behalf. Federer played all the tennis in the first four sets, he could have won all of them. And to then have two Championship points on his own serve, which is one of the most efficient. He tried to be bold on the second, but Novak Djokovic came up with the pass.”
Former Wimbledon champion Pat Cash on BBC Radio 5 Live Sports Extra: “It was a rollercoaster ride. It was amazing to see a tie-break in the end. There was nothing in that match in the end. You have to compliment both players. I was glad I got to witness this.”