The Swiss third seed, a five-time champion in New York, produced 19 unforced errors to surprisingly drop the first set against a player ranked 190th and without a tour-level win, AFP reported.
The 38-year-old recovered to progress 4-6, 6-1, 6-2, 6-4 and clinch his 1,224th career victory that set up a meeting with Bosnia's Damir Dzumhur.
"Maybe it's not a bad thing to go through a match like this. It was very similar at Wimbledon when I dropped the first set there, as well, in the first round," said Federer, who lost a five-set epic to Novak Djokovic in last month's final at the All England Club.
"At the end you look at the last three sets, and they were good. That's encouraging."
"I just wanted to pick up my game really, start to play better. I was able to do that. That was a relief, going up 3-0 in the second set, realizing that it is in my racquet, how I also felt it in the first set.
"The thing is I wasn't serving consistently enough. I was hitting double-faults that usually I don't do. Also I was just hitting too many unforced errors. I was in two minds, I guess."
Defending champion Djokovic said the timing of the US Open makes it the most unpredictable of the Grand Slams as the Serb made a promising start in his quest for a fourth title in New York.
The world number one, who has won four of the past five majors, brushed past Spain's Roberto Carballes Baena 6-4, 6-1, 6-4 in the opening round Monday.
He is attempting to become the first back-to-back men's US Open winner since Federer lifted the trophy five years running from 2004 to 2008.
"Well, maybe what I would point out is this Grand Slam is the last Grand Slam of the year. So some players maybe might have been more exhausted, less freshness in the legs, so to say, than is the case, for example, in Australia is the beginning of the season," said Djokovic.
"Because it's a long season, it's a lot of surfaces that you have to change and it takes a toll on your body.”
Reflecting on that dramatic finale against Federer at Wimbledon, Djokovic said the key to his remarkable recovery was to live "in the moment" in what amounted to a fight-or-flight situation.
"I think regardless whether you're an athlete or not, I think we all, as human beings, when we face this kind of adversity or major significant moment in our life, it seems like we're going to fail at something that we work so hard at trying to do," he said.
'I don't know who that is'
Serena Williams is trying hard to move past last year's US Open final meltdown, preferring to forget the umpire she called a "liar" and "thief" and fans booing a controversial ending.
Williams humbled Russia's Maria Sharapova 6-1, 6-1 on Monday to reach the second round of the US Open as she seeks a historic seventh New York title and 24th Grand Slam singles crown.
Asked if she felt the tournament was hers to win, the eighth seed replied, "I feel like I'm here to do that. We'll see what happens."
Her domination of Sharapova produced a 19th consecutive triumph over the five-time Slam winner, boosting her record in the rivalry to 20-2.
It was the first match for Williams at Ashe since she unleashed her wrath at umpire Carlos Ramos in last year's US Open final against eventual winner Naomi Osaka.
The US Tennis Association decided before the start that Ramos will not officiate any Serena or Venus Williams match at this year's US Open.
When she was asked about Ramos, whose penalty calls had a major impact in her loss to Osaka, she replied, "I don't know who that is."
Williams, when asked about how much last year's final entered her mind in her return to Ashe, spoke only about the crowd that was loud and vocal in supporting her over Sharapova.
"It was great. The fans, they were so amazing," Williams said. "I could hear them walking down the hallway. It was such a good feeling. It made me feel unbelievable, really helped me get amped up and pumped up."