Roger Federer was taken to five sets for the second time in three days before overcoming Russia's Mikhail Youzhny at the US Open.
The five-time champion was two sets to one down but eventually came through 6-1 6-7 (3-7) 4-6 6-4 6-2 in New York.
Federer has now won all 17 matches against Youzhny, a year younger at 35, since the pair first met in 2000.
Top seed Rafael Nadal required four sets to see off Japan's Taro Daniel in the night session.
The Spaniard, 31, trailed by a set and a break before two fizzing forehands turned the second set around and he went on to win 4-6 6-3 6-2 6-2.
"It's true that I didn't play very well tonight but at the same time it's true that I'm through to the next round," said the two-time champion.
It is the first time Federer has played five-set matches in the first two rounds of a Grand Slam.
"I think because you're on a high, you're thrilled that you got through, so you don't look at the negative," he said.
"Or I don't. Yes, I might feel more tired than I normally would going into a third round, but that's OK.
"My preparation hasn't been good at all here. I knew I was going to maybe struggle early on. Maybe I struggled more than I would have liked to.
"But I'm still in the draw, which gives me a chance."
The Swiss third seed goes on to face Spanish 31st seed Feliciano Lopez in round three at Flushing Meadows.
Five-time champion Roger Federer needed five sets to overcome American teenager Frances Tiafoe in the first round of the US Open.
The 36-year-old Swiss won 4-6 6-2 6-1 1-6 6-4 in his first ever match under the Arthur Ashe Stadium roof.
Third seed Federer goes on to face Slovenia's Blaz Kavcic or Mikhail Youzhny of Russia on Thursday.
Only nine players completed their matches as rain wiped out much of Tuesday's schedule.
Top seed Rafael Nadal beat Serbia’s Dusan Lajovic 7-6 (8-6) 6-2 6-2, before American 15th seed Madison Keys opened the night session with a 6-3 7-6 (8-6) victory over Belgian Elise Mertens.
They benefited from the stadium-court roof, which was not in place when Federer last played at Flushing Meadows two years ago, a knee injury forcing him out 12 months ago.
A crowd of almost 24,000 packed in to see his return to New York, but 19-year-old Tiafoe ensured they saw a far closer contest than expected.
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."
Rafael Nadal fell to a shock defeat by 18-year-old Canadian Denis Shapovalov at the Rogers Cup in Montreal.
Wildcard Shapovalov came from a set down to beat top seed Nadal 3-6 6-4 7-6 (6-4) and become the youngest player to reach a Masters 1000 quarter-final.
Nadal's loss means Andy Murray remains world number one, but only until next week's Cincinnati Masters, where Nadal or Roger Federer will replace him.
Federer also progressed to the last eight, with victory over David Ferrer.
The Swiss world number three, 36, came from a set behind to beat the Spaniard 4-6 6-4 6-2 and next faces Roberto Bautista Agut, also of Spain, who defeated Frenchman Gael Monfils 4-6 7-6 (7-5) 7-6 (6-2).
World number 143 Shapovalov, the 2016 Wimbledon junior champion, plays 29-year-old Frenchman Adrian Mannarino.
In the other quarter-finals, Germany's Alexander Zverev, who beat Australian Nick Kyrgios 6-4 6-3, will play South African Kevin Anderson,who saw off American Sam Querrey 6-4 6-1 in the last 16.
And Argentina's Diego Schwartzman will face Robin Haase of the Netherlands. Haase beat Bulgaria's Grigor Dimitrov 7-6 (6-3) 4-6 6-1, while Schwartzman defeated American Jared Donaldson 0-6 7-5 7-5.
Roger Federer became the first man to win Wimbledon eight times and extended his record to 19 Grand Slam titles with victory over Croatia's Marin Cilic.
The Swiss third seed won 6-3 6-1 6-4 as seventh seed Cilic struggled with a blister on his left foot and broke down in tears during the second set.
Federer, 35, finished the contest in one hour and 41 minutes to claim his first Wimbledon title since 2012.
He becomes the oldest man in the Open era to win at the All England Club.
"It is cruel sometimes," Federer said of Cilic's physical difficulties.
"But Marin fought well and is a hero, so congratulations on a wonderful tournament."
Federer surpasses Pete Sampras and William Renshaw, who won their seventh titles in 2000 and 1889 respectively, with only Martina Navratilova still ahead in terms of Wimbledon singles titles on nine.
He has won two of the three Grand Slam titles so far this year, having returned from a six-month break to win the Australian Open in January.
With 19 major titles he extends his lead over Rafael Nadal in the men's game to four, and now stands joint-fourth on the all-time list with Helen Wills Moody, five behind Margaret Court on 24.
Among his long list of achievements, Federer became the first man since Bjorn Borg in 1976 to win the Wimbledon title without dropping a set.
The tournament favourite from the outset, he was rarely troubled over the course of seven matches, and Cilic was not in the condition to provide a serious test.
"I never give up in a match. I gave it my best - it's all I can do," Cilic said afterwards.
Federer was playing in his 11th Wimbledon final and Cilic his first, and the gap in experience showed from the early stages.
Cilic, 28, hit a forehand which bounced before the net on the opening point as the nerves appeared hard to shake off.
Federer offered up a couple of early double faults but there was a sense of inevitability about the first break, which came in game five after Cilic fell heavily chasing down a drop shot, and then sent a backhand into the net.
A beautiful cross-court forehand helped Federer towards set point in game nine and Cilic duly double-faulted, ending the set with a 49% first-serve percentage that hardly troubled the Swiss.
After Federer made it 3-0 in the second set, a tearful Cilic sat in his chair as the doctor, tournament referee and supervisor attended to him.
Roger Federer and Novak Djokovic made swift progress with straight-set wins in the second round at Wimbledon.
Third seed Federer, seeking a record eighth title, beat Dusan Lajovic 7-6 (7-0) 6-3 6-2 on a hot evening on Centre Court.
Djokovic, seeded second, earlier swept past Adam Pavlasek 6-2 6-2 6-1 on Court One.
Sixth seed Milos Raonic, eighth seed Dominic Thiem and 10th seed Alexander Zverev secured places in round three.
Swiss Federer and Djokovic of Serbia both completed matches for the first time this week after their first-round opponents had retired with injuries.
Three-time champion Djokovic needed just over 90 minutes to see off Czech Pavlasek, the world number 136 making his debut at the Championships.
The 30-year-old will play Latvia's Ernests Gulbis, after the world number 589 beat Argentine Juan Martin del Potro 6-4 6-4 7-6 (7-3).
"Overall I managed to impose my own rhythm and play the game I intended to play," Djokovic, who converted seven of his 18 break points, told the BBC.
"It was very warm and hot and not easy to play point after point in some of the long rallies."
Federer, 35, lost the opening seven points and fell 2-0 down against Lajovic, who played well above his ranking of 79 for much of the contest.
It was still not enough to seriously trouble the Swiss, watched by his parents in the royal box.
Federer broke back immediately and after a tight set, dominated the tie-break to take decisive control of proceedings.
Ninety minutes, nine aces and 30 winners later, he wrapped up a solid win and a third-round clash with Germany's 27th seed Mischa Zverev.
"I struggled early on. I couldn't get rid of the nerves and struggled to find my rhythm," Federer told BBC Sport.
"I should feel comfortable here, and I do, but the problem is on grass if you're struggling it can take a while.
"I wasn't too worried. Nerves are a funny thing, sometimes you get horribly nervous and other times it's a piece of cake. I'm happy it happened in the second round."