The 42nd-ranked Granollers surprisingly led the second-seeded Swiss 5-2 when lightning and heavy rains suspended their afternoon match at Arthur Ashe Stadium.
After play resumed a couple of hours later, 17-times grand slam winner Federer conceded the first set and trailed 1-0 in the second before taking 18 of the next 20 games to secure victory.
"I was able to come back and turn it around, because Marcel started really on fire," 33-year-old Federer told the crowd. "I'm happy the break helped me and I came out and played some great tennis."
Federer holds the all-time men's record for most grand slam singles titles but has come up empty over the last eight dating back to the 2012 Wimbledon tournament.
With his nemesis Rafael Nadal, the 2013 US Open champion, missing the tournament with a wrist injury and the Swiss playing in the softer side of the draw, this could be a great chance for Wimbledon runner-up Federer to add to his record total.
Federer said he is feeling great and looking forward to this opportunity in his 60th successive grand slam appearance.
"It's been really excellent the last three matches here at the US Open," said Federer, who lost his first set of the tournament against Granollers.
"I feel very explosive, quick. The coordination is there as well. I feel like I've gotten used to the hard courts by now. It's really working well. I'm very pleased.
"I'm happy I wake up every day and I'm ready to go.
"I think when you keep yourself in shape and train the right way, that's how you do it ... it's become a game of movement."
- Sports & Recreation
- Roberto Bautista Agut