Roger Federer came from a set down to beat Damir Dzumhur 3-6 6-2 6-3 6-4 under the Arthur Ashe Stadium roof to reach the US Open third round.
The world number three hit 17 unforced errors in losing the first set.
But the Swiss five-time champion dominated the remainder of the match to defeat Bosnian world number 99 Dzumhur.
Victory for the 38-year-old sets up a third-round match against either Britain's Dan Evans or Frenchman Lucas Pouille at Flushing Meadows.
"I just tried to make less errors and be better on the offensive. I was able to protect my serve after a sloppy first set," Federer said.
"There were some big moments. I came through, buckled down and told myself I was not going to get broken, stayed tough and hung with him and that helps with my confidence for the next match."
Federer dropped the opening set in his first-round win over Indian qualifier Sumit Nagal and he made another slow start here, losing the first four games of the match.
Although he retrieved one of those breaks, 27-year-old Dzumhur served out the set and held a break point in the opening game of the second set but could not convert.
Federer then immediately broke with a forehand winner and levelled the match through another break when Dzumhur double-faulted.
The Swiss broke at the first opportunity in the second set but had to save four break points in the seventh game as Dzumhur continued to push him.
After sealing the set with an ace, a forehand winner allowed Federer to break in the third game of the fourth set and he went on to seal victory in two hours and 22 minutes.
Federer hit 16 aces to Dzumhur's two and 58 winners overall - more than double his opponent's 26.
Play was delayed on the outside courts on Wednesday because of rain in New York, with Britain's Johanna Konta set to face Margarita Gasparyan when the weather improves. Dan Evans will take on world number 27 Lucas Pouille.