Federer went behind to Sumit Nagal in his first-round match and suffered a similarly slow start in Wednesday's contest on Arthur Ashe Stadium.
But, much like in round one, the five-time Flushing Meadows champion - who made 45 unforced errors - found his form and once he nosed ahead in his 100th US Open match he never looked like slipping up.
The World No. 3 was not handed it on a plate and although Dzumhur kept himself in it with some fine shots in the final set, Federer served out the win with the first match point on offer.
Dzumhur raced out of the blocks and stormed into a 4-0 lead after a second successive break.
Federer returned the favour in game five, but Dzumhur recovered from 30-0 down on his next service game - a sensational backhand slice forcing the former World No. 1 to serve to stay in the set.
Federer did so successfully, but his opponent had his tail up and seized a one-set lead with just 29 minutes on the clock.
Another unforced error from the third seed handed Dzumhur a break point in the first game of set two, but the 27-year-old could not take his chance.
Federer made no such mistake, catching the Bosnian cold with a slick forehand down the line before executing a perfect drop shot en route to restoring parity.
A stunning cross-court backhand indicated Federer had hit his stride and the 38-year-old did well to save three break points for a 5-2 lead in the third.
With Dzumhur receiving treatment for an apparent side issue during changeovers, the Swiss closed out the set in his favour on his next serve.
Dzumhur's frustration at conceding his advantage started to show in set four, with a sloppy serve handing the 20-time grand slam champion a break in game three.
The finish line was in sight and Federer did not look back, finally breaking Dzumhur's resolve to set up a third-round clash with either Dan Evans or Lucas Pouille.