'It's going to give me great confidence'

A slow start, first-serve percentage of 54%, and 56 unforced errors were evidence that Federer was well short of his best, but he was happy to come through after a build-up disrupted by a back injury.

He first felt the problem in the Montreal final three weeks ago, and subsequently pulled out of the Cincinnati Masters.

"I was maybe a bit worried from the beginning with my back issue, but eventually I was able to let go," said Federer.

"If I felt that my back was going to get worse every match, I probably wouldn't have played. My hope and belief is that it's only going to get better."

The Swiss has yet to lose a Grand Slam match this year, having won his 18th and 19th major titles in Australia and at Wimbledon, while skipping the French Open.

Few expected Tiafoe, the world number 70, to trouble him greatly, but in a match where errors far outstripped winners, amid wild swings of momentum, the teenager ran him close.

Asked how he felt at the end of the match, Federer said: "Extremely well. To get through a five-setter you have to be OK.

"It's going to give me great confidence in the body and in my game, because preparation was a little bit compromised, so I'm really, really happy with tonight."

Twists and turns in strangest of matches

Federer looked uncomfortable in the early stages, miss-hitting two backhands on his way to dropping serve immediately.

One break was enough to give Tiafoe the opening set but after 70 minutes or so, Federer began to move more freely and he raced through sets two and three.

That form faded, though, and Tiafoe managed to take it into a fifth set despite having made 16 winners to 40 errors.

A poor drop shot in game four of the decider allowed Federer to swat away a backhand and seemingly close in on victory.

However, this strangest of matches took another turn as the Swiss failed to convert a match point and was then broken by a rasping Tiafoe winner.

It proved to be a last flash of resistance, though, as the American played another loose service game to offer up two more match points, and dragged a forehand into the net on the second.

'He got it going when he needed to'

John McEnroe, four-time US Open champion, on ESPN:

Federer should still be the favourite. If he has a back issue that becomes more troubling then that would be a cause for concern.

The timing was not as exceptional as at the Australian Open or Wimbledon, but nonetheless he got it going when he needed to. He got through, he's going to have couple of days, he's got a pretty good looking draw, so he's going to be able to regroup.

If that back holds up, you'll see him play better and better tennis.

Analysis

BBC tennis correspondent Russell Fuller:

Federer was unrecognisable from the man who won Wimbledon without dropping a set as he made 18 unforced errors - the majority on the backhand - to lose the opening set.

Gradually he slipped into a much better groove, assisted by Tiafoe, who lost his way after an excellent start. But in set four, the roles were reversed to set up a thrilling climax in front of a partisan crowd, who for the most part weren't backing their own man.

Federer's fitness may prove to be an issue as the fortnight develops, but he has at least lived to fight another day.