Federer, a 20-time Grand Slam champion, fired 16 aces and rallied to dispatch 99th-ranked Dzumhur 3-6, 6-2, 6-3, 6-4 under the roof at Arthur Ashe Stadium.
Five-time US Open winner Federer, who lost to top-ranked Novak Djokovic in last month's epic five-set Wimbledon final, hasn't fallen in a Slam second round since 2013 at Wimbledon.
Federer, who also dropped the first set against Indian qualifier Sumit Nagal in his opener, struggled early but again answered the wake-up call after conceding the first set.
"Very similar to the last one," Federer said. "I tried to make less errors and be aggressive. It just takes me some time I guess."
He broke to 2-0 in the second set with a forehand winner and took the final game when Dzumhur double-faulted.
Federer broke again in the second game of the third set and rolled through, then blasted a forehand winner to break for a 2-1 edge in the final set and held from there to advance.
"I was able to save my serve after a sloppy first set," Federer said. "I came through. I buckled down and told myself I was going to hang tough and not get broken and that made a big difference."
Next in Federer's path is the winner of a later match between French 25th seed Lucas Pouille and Britain's 58th-ranked Dan Evans.