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.
"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. 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."
More From This Section
Federer said he was surpised to have got to a deciding set.
"It was a great final. I can't believe I made it to five, it wasn't looking good for a while," said Federer.
"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.