If Andy Murray had played in a crown of thorns, hair shirt and bare feet on broken glass he could hardly have suffered more in victory than he did against Milos Raonic here.

The Scot arrived in London this week playing the best tennis of his career, unbeaten for more than three months, winner of four consecutive titles and ranked No1 in the world. After an hour of the first semi-final of the Barclay’s ATP World Tour Finals, he was misreading the simplest tenets of tennis as if they were a total mystery to him. Somehow he beat his opponent and won the struggle he was having with his own game, but it took him a record three hours and 38 minutes. He will surely be aching ahead of the final on Sunday.

Murray railed at himself and everything else, inanimate objects and those breathing heavily on his behalf throughout the packed arena, in good moments and bad. It was a tour de force of self-admonishment, a triumph of doggedness. But, yet again, he delivered. He is phenomenal – even when he is not playing phenomenally well.

Andy Murray v Milos Raonic: ATP World Tour Finals – as it happened Read more

Murray went on to win 5-7, 7-6, 7-6 and reach the final from his fourth semi‑final here. If he wins it, the 29-year-old Scot will remain No1 in the world at the end of his season, the oldest player to do so since John Newcombe in 1974.

“I had to fight very, very hard,” he said courtside. “It was tough going into the [third-set] tie-break, having been broken twice serving for the match. Just managed to get there in the end. It was an amazing atmosphere.

“The longer the match went on the louder the crowd got. This is what we play for.

“It’s one of the harder matches I’ve played indoors, two matches over three hours. You don’t expect that, especially against Milos. I’m obviously tired. Played so much matches over three months, and this week. I’ll give it my best shot [in the final].”

He could hardly have made a brighter start, holding to love – about the time Olivier Giroud was equalising for Arsenal, his favoured London team, at Old Trafford to preserve an unbeaten run stretching back 16 matches to mid-August, which was roughly when Murray embarked on his own run of 23 wins, the more recent of which have taken him into his first final here in 10 attempts.

He did not drop a point on his serve until the match was a quarter of an hour old, in the fifth game, and then he had to save break point as Raonic finally found a rhythm. What followed was an exchange of errors longer than a dunce’s exam paper.

If Murray had thought this might be a straightforward afternoon’s work, he was disabused of the notion in the ninth game, which went on for 12 agonising minutes before Raonic squandered a fourth break point with three wild forehands.

In Paris two weekends ago, Raonic’s right quad gave up on him and he was unable to play Murray in the semi-final.

Here, at 6-5, the set was in his hands, rather than his legs. Murray saved two of three set points then dumped a return into the net.

Facebook Twitter Pinterest Andy Murray cut a frustrated figure throughout the match, which lasted for more than three hours. Photograph: Kirsty Wigglesworth/AP

Raonic has a 48-6 winning record this year when going in front but, pointedly, two of the six were against Murray, at the Australian Open and Queen’s. By the time they got to the Wimbledon final, Murray had pretty much sorted him out, winning in straight sets.

After an animated debate with the chair umpire between sets, it was clear he was still searching for his best tennis. He netted the sloppiest of forehands to hand Raonic a 2-0 lead, and it was looking decidedly grim for the player who had received a standing ovation on each of his four visits to the court this week.

True to his own remarkable history, he broke back to love. They both had found another level of intensity, and Murray should have broken to take the set in the 10th game, but nerves struck and the chuntering increased.

The slackness of shot that had wrecked his game an hour earlier briefly gripped him again by the time they got to the tie-break. Murray needed all of his famous resolve against an opponent who figures in the top 10 in all six categories of serving proficiency in the ATP computer statistics.

Murray won both their tie-breaks in his three-set win at Wimbledon and held a 29-1 winning record for the season going into this one. Raonic lost two tie‑breaks this week to Novak Djokovic, and won one against Dominic Thiem. He lost this one too.

In the players’ box, Murray’s wife, Kim, got to her feet, shook her fist and screamed at him: “Come on! One more!” It looked and sounded like a command rather than a request. After asking for the spidercam to be moved out of his line of vision, he served through deuce to level at four-all.

The final fluctuations mirrored those that had gone before. After three hours, they each had won 116 points. Raonic missed with a 129mph serve in the ninth game, botched his next forehand, pelted the net with another and Murray served for the match. Raonic, muttering “come on” all match, attacked Murray’s serve with desperate intent, smashing an unreachable winner to get back to five‑all.

In the 11th game, Raonic double-faulted, his sixth of the match. He slammed the net with a forehand and Murray served for the match for a second time.

Again he gave up two break points. Again he botched his final shot. And again they went to the shootout. It was as if we had all walked into a remake of Groundhog Day.

The Canadian saved four match points but did not have enough strength in his final forehand, and the match was Murray’s. The relief in the arena was immense.