In a final as memorable for its longevity and unfathomable swings of fortune as the quality of shot-making by two of the finest grass-court players of any era, Novak Djokovic ground down the classical skills of the ageless Roger Federer to win his fifth Wimbledon.

For four hours and 57 minutes, they resided side by side in the land of lost opportunities, before the world No 1 brought their mutual bewilderment to a close to win by the unique scoreline: 7-6 (5), 1-6, 7-6 (4), 4-6, 13-12 (3).

Novak Djokovic v Roger Federer: Wimbledon men's singles final – live! Read more

Federer had two match points at 8-7 in the fifth, but ended up losing the first 12-all tie-break to decide the title – and his third shootout of the match, one as mesmerising and strange as any of the 48 they have played.

“I feel great, I gave it all I had,” Federer said courtside. “I’m still standing. I’ll take some time to recover.”

Djokovic said: “If not the most exciting and thrilling finals of my career, in the top two or three and against one of the greatest players of all time. As Roger said, we both had our chances. It’s quite unreal to be two match points down and come back – and a bit strange to play the tie-break at 12-all. Roger said he hopes it gives other people hope they can do this at 37. I’m one of them. It’s extra special with my son in the crowd, and my family too. My wife and daughter are here in London but watching at home, and I give them a big, big hug.”

It was as if this weirdest of finals was directed by some perverse supernatural force, determined to destroy normal perceptions of logic and fairness.

But sport is not always fair. And there can be no denying Djokovic his triumph, built on bloodymindedness and perseverance. Federer, who played some of his most glorious tennis, was left to lament a string of squandered chances, and he knows there will not be many more left for him.

The Swiss, 38 next month and in his 12th final here reaching for his ninth championship, went for his shots from the start. The crowd were predictably and unashamedly partisan, groaning at every Federer error, exulting in Djokovic’s. If he were representing the world against Mars, the planet could have no more popular champion.

But even Middle England’s finest, in their lavender and lemon crispness on a mellow Sunday afternoon in the hallowed sanctuary of their favourite mid-summer diversion, had to rise to an outrageous backhand by the world No 1 that left their man standing in the eighth game, as these extraordinary players stayed on level terms on the half-hour.

Facebook Twitter Pinterest Roger Federer is distraught after losing in five sets. Photograph: Victoria Jones/PA

Federer aced for the third time to lead 5-4. He played quite brilliantly with touch at the net and power from deep to threaten the Djokovic serve. An ace steadied the boat but a double fault nearly capsized it in a nervous hold. Federer double-faulted for deuce, but held. Djokovic aced twice to force the tie-break. The tension mounted. This was a slightly bigger crunch for the older man (lethal in shootouts this year at 15-3), but it was Djokovic who held his nerve to go a set up just short of the hour.

Courage in the shot – the virtue for which everyone loves him – cost Federer the set, and he now had to come from behind against the best defender in the game. But Djokovic had slipped into tennis limbo, shot after shot falling short or sailing long. Just as Federer had thrown the second set against Rafael Nadal in the bin on Friday, so Djokovic did here. Now they had to start all over again, but the momentum and the sentiment were inarguably with Federer.

Djokovic carried his second-set ennui into the third and looked exasperated as Federer’s serve continued to torment him. Federer was playing as close to perfection as even he was capable of; Djokovic had the air of a drowning man, his serve a feeble foil for the Swiss knife digging in his ribs.

Djokovic spent more energy shaking his head than Federer did rifling home one killer serve after another. Then, against all odds, they went to a second tie-break; against all odds, Djokovic won it, almost blowing a 5-1 lead; against all odds, he was in front – after playing for two and a half hours and not creating a single break opportunity. This was an insane match. Meanwhile, Federer – who confessed to exhaustion after four sets against Nadal and needing to win two more here – broke Djokovic for the fourth time to go 3-2 up in the fourth. Somehow, the action had reverted to the feel of the second set, where Federer looked as if he could fly, and Djokovic seemed barely able to walk.

After two hours and 47 minutes, Djokovic finally got a break point – and 35 shots later, the longest rally of the match, Federer saved for deuce. Within seconds, Djokovic got another look, and broke for 3-5. Federer nevertheless held to love for two sets all. The craziness refused to die.

Now, as against Nadal in 2007, when he won, and 2008 when he lost, as well as 2009 when he beat Andy Roddick and 2014, when Djokovic beat him, Federer was dragged into a five-setter to decide the championship.

The question mark was over his lungs, not his heart. The latter beat strongly all the way to the end, the former sucked harder by the second at the warm, still air. He needed every ounce of his resilience to save three break points in the fourth game.

Sign up to The Recap, our weekly email of editors’ picks.

Djokovic was tired too, but five years younger. After a tense hold for 5-4, Djokovic, clearly running on old instincts, asked the chair umpire, “When do we play the tie-break?” He was informed: “12-all.” Moments later, he came within two points of victory, when Federer butchered a volley for deuce before getting to six-all. And on they laboured.

When Federer served to extend the drama for a sixth time at 10-11, the fifth set had been going an hour and 36 minutes, a tick longer than his second-round win over Britain’s Jay Clarke.

Federer held his serve to force the third tie-break. Djokovic fashioned three championship points. When Federer framed his final forehand, they dragged themselves to the net, briefly embraced and probably wondered exactly where in the world they were standing, so surreal was the day and the match.

• This article was amended on 15 July 2019. An earlier version missed out the words “one of” from a quote by Djokovic. The full phrase referred to Federer as “one of the greatest players of all time”.