LONDON —Novak Djokovic may not have been the better player from first ball to last in Sunday's Wimbledon men's final.

But he summoned nerves of steel when it mattered most, blasting the shots, avoiding the costly errors and saving the two match points required to defeat eight-time Wimbledon champion Roger Federer, who had artistry and the Centre Court crowd on his side in his pursuit of a 21st Grand Slam title.

The 37-year-old Federer was the aggressor, hitting 94 winners to Djokovic's 54, and he ultimately won more points (218 to 204). But it was Djokovic's trophy to raise at the end of an exceptionally contested match that lasted 4 hours 57 minutes - the longest final in Wimbledon history.

With his 7-6 (7-5), 1-6, 7-6 (7-4), 4-6, 13-12 (7-3) victory, Djokovic claimed his fifth Wimbledon championship and the 16th major of his career to pull within two of Rafael Nadal's total and four of Federer's all-time mark, which for now is paused at 20.

It was Wimbledon's first singles championship settled under the tournament's new tiebreak format, which was instituted this year and kicks in if the fifth set is knotted at 12 games each. The format was instituted to prevent soul-sapping marathons such as the three-day affair between John Isner and Nicolas Mahut in 2010, which dragged on until 70-68 in the fifth set, and last year's semifinal between Isner and Kevin Anderson, which lasted to 26-24.

Djokovic called it the most mentally demanding match he had ever been part of and credited the victory, which he acknowledged could easily have been Federer's, to will power and the mental and emotional aspects of his game that he has worked so hard to strengthen.

"Most of the match I was on the back foot, actually," said Djokovic, 32. "I was defending; he was dictating the play. I just tried to fight and find a way when it mattered the most."

Already the world's top-ranked player, Djokovic has now won four of the past five majors, closing in quickly on the standard of perfection Federer has set in his two-decade pro career. Federer acknowledged afterward that the match was "an incredible opportunity missed," having let two match points and other opportunities slip away.

But asked about the steady assault by Nadal and Djokovic on his record of 20 Grand Slams, Federer came across as a man at peace.

"If somebody else does (break the record), well, that's great for them. You can't protect everything anyway," Federer said. "I didn't become a tennis player for that. It's about trying to win Wimbledon, trying to have good runs here, playing in front of such an amazing crowd in this Centre Court against players like Novak and so forth. That's what I play for."

Sunday's final was the 48th meeting between Djokovic and Federer. And it was fitting that the Wimbledon title came down to them, the field of 128 narrowed to the tournament's No. 1 (Djokovic) and No. 2 (Federer) seeds. They were greeted by rousing cheers and a standing ovation when Djokovic led Federer onto Centre Court just before 2 p.m. Looking on from the front row of the Royal Box were the Duke and Duchess of Cambridge, with 80-year-old Rod Laver, the inspiration for both finalists, just behind, along with former Wimbledon champions Stefan Edberg, John Newcombe, Manuel Santana and Stan Smith.

To have a chance, most prognosticators said, Federer needed to win the opening set. The proceedings veered from that script.

Federer took the higher-risk approach in a first set of exceptional shot-making and touch. There was scarcely a grass-blade's difference between them in quality, so it came down to a tiebreaker that Djokovic claimed.

If Federer was frustrated by 58 minutes of wasted effort while dropping the opening set, he redirected it magnificently, bolting to a 4-0 lead in the second while Djokovic took a mental walkabout, much as he had in Friday's semifinal against Roberto Bautista Agut after claiming the opening set before winning in four. With the Serb seemingly disengaged, Federer needed just 25 minutes to level the match by claiming the second set.

The match unfolded with utter silence from the competitors. There wasn't a grunt, groan or shout of "C'mon!" between them - whether the restraint reflected their respect for each other, for their sport's most hallowed venue, or was a tactical decision to devote their energy into each point.

In Djokovic's case, he explained, it was the latter.

"I promised myself coming onto the court today that I need to stay calm and composed," he said, "because I knew that the atmosphere will be as it was."

In other words: a lovefest for Federer, whose game and grace are custom-tailored for Wimbledon's grass.

The third set was as tightly contested as the first, and once again a tiebreak was required. The Serb jumped to a 4-1 lead and held on to take a two-sets-to-one advantage.

The physical and psychological toll should have been profound for Federer. But instead of fading in the fourth set, he broke Djokovic's serve in the third game and held his own to take a 4-2 lead that thrilled the crowd, which erupted in cheers for the Swiss and the prospect of a fifth set.

The crowd got its wish. Federer and Djokovic produced a fifth set that alone was worth the price of admission - 2 hours 2 minutes long and full of swings of momentum, breakpoints and heroic comebacks.

Djokovic was first to nudge ahead 4-2 after breaking Federer's serve for just the second time in the match. When Federer immediately broke back, even guests in the Royal Box dropped any pretense of impartiality, cheering the fight left in the Swiss.

This is where another mental trick of Djokovic's kicked in - "transmuting" the noise, he called it afterward.

"When the crowd is chanting, 'Roger!' I hear 'Novak!' " he explained. "It sounds silly, but it's like that. I try to convince myself that it's like that."

At risk of losing his serve at 5-5, which would have essentially gift-wrapped the victory for Federer, Djokovic lunged to stab back a winning volley. Neither man budged.

So at 6-6, the match just shy of the four-hour mark, they played on for the two-game lead required to win the fifth set. The stadium erupted when Federer got the service break he needed by toying with the pace and trajectory of his shots and coaxing Djokovic into errors. The match was on his racket.

Djokovic roared back, saving two match points to draw even again at 8-8.

And on they played, until a miscue by Federer ended it.

Djokovic pointed to the sky, then calmly strode to the net. There, they shared an embrace: one victor, but two champions who had an equal part in tennis history.