Mikhail Youzhny, who had not beaten Roger Federer in 16 attempts, defied cramping to expose the Swiss’s worrying frailties before falling in five sets in the second round of the US Open on Thursday.

Federer won 6-1, 6-7 (3), 4-6, 6-4, 6-2 in front of a perplexed and often concerned audience on the main court, Arthur Ashe, but he hardly erased the unpalatable memory of nearly losing to the American Frances Tiafoe over the same distance in the first round. If he cannot tap into the inspirational tennis that lifted him to triumph in Melbourne and Wimbledon this year, his progress in New York is in serious jeopardy.

“It wasn’t always like this, but these five-set battles are a lot of fun,” he said courtside to some incredulity. “I feel quite warmed up now … I haven’t played a lot of guys with cramps over a decade or so. It’s hard to watch, but that’s how it is. We go way back to ’98 junior doubles here. This was probably our best match.”

There was no reason to believe the Russian presented anything more than makeweight opposition for Federer, whom many observers have as favourite to win a sixth US Open title, breaking a nine-year drought here in his golden comeback season.

It took Youzhny, only a year younger than Federer at 35, more than 20 minutes to get on the board but the set was Federer’s within moments and he had barely broken sweat. There was no hint of the drama to come.

Pride bruised, Youzhny won eight of 12 points at the start of the second before Federer broke for the third time. Even then, there seemed little cause for concern. Soon enough, though, he was hanging on in the tie-break – which Youzhny clinched against all expectations. In 49 minutes the whole complexion of the match had changed.

The mistakes mounted at an alarming rate, the drop shots fell like soggy fruit, the net grew bigger, the serve lost its smooth potency, mistimed forehands drifted long, his backhand was limp and his feet did not move with their familiar lightness. Everything seemed wrong as premature celebration morphed into lingering concern. He had already racked up 28 unforced errors with many more to come.

The South African Cliff Drysdale, who has seen it all and is one of ESPN’s most astute analysts, observed: “He is playing to me like he is tight. But I cannot come up with one reason why.”

Federer had to serve to stay in the set again, this time a break down. A butchered backhand of a routine volley and a lazy long forehand cost him two set points before he scrambled to safety in a deft exchange of light touches at close quarters. Youzhny, though, held to love, and his self-belief soared.

While his 2017 highlight was losing to Roberto Bautista Agut in the quarter-finals in Chennai, he was leading Federer two sets to one at the US Open, a tournament where he had reached the semi-finals twice before.

Then the pendulum swung back violently. Federer raced to 4-1 as he rediscovered his fluency and Youzhny went into minor meltdown, calling on the trainer for running repairs and a mental rest. Federer toyed briefly with his stricken foe before falling over the line to take the fourth set as Youzhny, struggling physically, failed to grab the moment.

The Russian fell awkwardly when reaching for a lob in the third game of the fifth set, and, grabbing at his thigh, limped from there to the end. And still Federer struggled to finish it. He needed help; Youzhny opened the door for him in the sixth game with his eighth double fault - and Federer replied with his 12th ace, a superb drop shot, another ace and a nonchalantly tapped volley for 5-2. It was as if there never had been a hint of a crisis.

Youzhny, serving lollipops, saved one match point but not a second, as Federer smashed his shanked lob hard into the ground for one of the least convincing wins of his slam career.

Earlier, Grigor Dimitrov left the tournament in the most miserable fashion, losing in straight sets to a young opponent he probably would recognises as mirroring his own precocious rise, Andrey Rublev.

The feisty teenager could take only five games off Andy Murray the Australian Open this year but was too hot for an underdone Aljaz Bedene in the second round here. Dimitrov, who won Cincinnati two Sundays ago and looked to be recovering much of his old lustre, served 11 double faults and was powerless to find a way past the occasionally volatile son of a Russian amateur boxing star. Rublev finished it with a sublime running forehand past the Bulgarian’s forehand, to win 7-5, 7-6 (3), 6-3.