Victory allowed the top seeded Serb, who was also the 2011 champion and runner-up last year, to end a run of three successive defeats in Grand Slam finals, but the 27-year-old struggled to get across the finish line, surrendering a 5-2 lead in the fourth set and then a match point.
Djokovic celebrated victory in typically eccentric style, kneeling on the Centre Court turf and munching on a few blades of grass just as he had done three years ago.
Defeat for 32-year-old Federer, who won the most recent of his 17 Grand Slam titles at the All England Club in 2012, ended his bid to become the oldest Wimbledon champion in the Open Era and of breaking the tie of seven titles he shares with Pete Sampras.
"First of all I want to congratulate Roger it was a great match to be a part of he is a magnificent champion and a great example of a great athlete and a role model. I respect everything you have done and thanks for letting me win today," smiled Djokovic.
"That's why he has 17 Grand Slams because at important times he comes up with those shots," he said.
"After losing the fourth set it wasn't easy to go on and win the fifth set, I don't know how I did it."
Djokovic has the added bonus of reclaiming the world number one spot from Rafael Nadal.
Federer said he was surprised to have got to a deciding set.
"It was a great final," he said.
"I can't believe I made it to five, it wasn't looking good for a while," he said.
"Going into a match with Novak, you know it's going to be tough. I can only say congratulations to him. It was an amazing match and an amazing tournament. It's well-deserved."
In front of a Royal Box containing Prince William and wife Catherine, the opening set was a fascinating contrast between Federer's mix and match of serve and volley and Djokovic's renowned baseline flair in the pair's 35th meeting.
Two rallies featured 21 strokes apiece but neither player could fashion a break point.
In a rollercoaster of a tiebreaker, Federer saw a 3/0 lead gobbled up and then had to save two set points.
But the Swiss rallied when it mattered, taking the opener when Djokovic dumped a backhand return into the net.
The Serb took a nasty tumble on the bone-dry grassless baseline and saw two break points disappear in the first game of the second set.
But he did break in the third for 2-1 -- just Federer's second loss of serve of the tournament — before calling the trainer to treat the left ankle he hurt in the fall.
Federer had his first break point of the tie in the 10th game but Djokovic saved it and levelled the final with a brutal overhead.
Federer saved two break points in the 11th game of the third set, moving to 6-5 with a 20th ace.
But it was Djokovic who was on top in the tiebreaker charging to two set points and the third set when Federer pushed a drive wide.
In a thrilling fourth set, Djokovic broke for 3-1, Federer hit back for 2-3 but the Serb regained the initiative for 4-2 and held a nervy seventh game for 5-2.
Astonishingly, back came the veteran Swiss to go to 4-5, breaking his opponent when he served for the title.
He saved a match point in the 10th game on a successful challenge to take the final into a decider.
Djokovic led 2-1 in the fifth and called the trainer for the second time for treatment to his right calf.
The man from Belgrade fought off a break point to lead 4-3 and then wasted three of his own as the rivals went to 4-4.
Djokovic held for 5-4 and from nowhere he seized the initiative, moving to two championship points and clinched the trophy when Federer netted a return.