Ragged Roger Federer recovered from dropping the first set of his US Open campaign to squeeze past Indian qualifier Sumit Nagal.
Nagal, a 22-year-old from New Delhi playing in his first grand slam, could not believe his luck as the 20-time major champion made 19 unforced errors to gift him an unlikely lead.
The Swiss great's timing seemed to have deserted him as straightforward forehands floated wide and backhands looped high and long.
The build-up to the first-round match centred around not confusing Nagal with his near-namesake Rafael Nadal, yet 35 minutes in the scoreline only seemed credible had Federer been facing the Spaniard.
However, Federer also lost his first set at this year's Wimbledon to little-known Lloyd Harris, and went on to reach the final.
The 38-year-old bucked his ideas up at the start of the second set, breaking Nagal with a fourth break point, and then repeating the dose to take a 5-0 lead.
Federer was by now hitting the lines he had previously been missing by a distance and the match was quickly level, although Nagal was still enough of a nuisance to save six set points before succumbing.
But Nagal's hustling was no longer hassling Federer, a double break in the third putting him firmly in control.
There was no way back for Nagal, despite another break in the fourth, and a relieved Federer's 4-6 6-1 6-2 6-4 victory was wrapped up with an unreturnable serve.
By contrast, defending champion Novak Djokovic made short work of Spain's Roberto Carballes Baena to reach the second round.
The world number one and top seed, bidding for a 17th grand slam title, won 6-4 6-1 6-4 in just under two hours.
"It's great to be back," said Djokovic, who has never lost in the first round at Flushing Meadows.
"I'm obviously grateful that at this stage of my life and my career that I'm still able to play at this level on this special court.
"I've never faced Carballes Baena before, he's solid from the back of the court so I'm pleased with my performance.
"Obviously getting out of the blocks takes a bit of time, but in the first set I had some break points and managed to capitalise on the big moments. I know what I need to do, to keep going."
Daniil Medvedev is Djokovic's likely quarter-final opponent and the fifth seed from Russia cruised past Prajnesh Gunneswaran.
Medvedev, who beat Djokovic on his way to winning in Cincinnati earlier this month, triumphed 6-4 6-1 6-2.
Stan Wawrinka, the 2016 champion, needed four sets to see off Italian youngster Jannik Sinner but Japan's Kei Nishikori, the seventh seed, had an easy passage after Marco Trungelliti retired injured in the second set.
Italian Fabio Fognini, the Italian 11th seed, was the highest-ranked first-round casualty as he crashed out to American beanpole Reilly Opelka in four sets.