World No.4 Federer was dominant in the opening set but was pushed in the second before he wrapped up the 6-1 7-5 in one hour and 17 minutes.
"I struggled a little bit with my serving in that second set and that gave him some chances", Federer said.
That victory gave the Serbian his third consecutive Grand Slam title after last year's Wimbledon and US Open triumphs.
Osaka will next face Australian Open semi-finalist Danielle Collins, who thrashed Kirsten Flipkens.
Seven-time Grand Slam champion Venus Williams went down early in the first set, but fought her way back to topple third seed Petra Kvitova 4-6, 7-5, 6-4 to reach the third round.
Stressing on the importance of enjoying her game, she said, "I just want to do the things that I practice and know that I can do well and even if things aren't going my way try to find a way to win matches".
He next faces Argentina's Diego Schwartzman, a 6-3, 6-1 victor over Spain's Roberto Carbralles.
Despite Kvitova firing down 10 aces, it was nullified, as she also hit ten double faults, gifting Williams the free points.
The second-round clash was the world No.1's first match since he won his seventh Australian Open title in January.
Lakers, Carmelo Anthony ‘pause’ talks of deal, report says
Over the course of his career, Anthony has averaged 24.0 points, 6.5 rebounds and 3.0 assists per game. He now trails only Kareem Abdul-Jabbar (38,387 points), Karl Malone (36,928) and Kobe Bryant (33,643).
"He's the best player to ever play the sport", Wawrinka said.
Osaka, who was able to win the Australian Open just a few months back, said that she finds it hard to adjust with the people's expectations.
Roger Federer saved four break points to defeat Peter Gojowczyk yesterday. And I think I created some opportunities.
Kvitova seized a break lead again in the third, but Venus took the last three games of the match to win it.
"It sounds bad saying it but it's true because I never really went far in a tournament like this". I was so frustrated with myself from the half of the second set to the end, which shouldn't happen to me.
Women's fifth seed Karolina Pliskova started on a rusty note, but eventually beat Japanese qualifier Misaki Doi 6-7 (4/7), 6-1, 6-1.
"I just started to miss so much, and I didn't put the first serve in".
Elsewhere, eighth-seeded German Angelique Kerber eased into the third round with a 6-0, 6-2 victory over Kazakhstan's Yulia Putintseva.
Russian 14th seed Daniil Medvedev is also through after he dismissed American Mackenzie McDonald 7-5 6-0 and he will face Filip Krajinovic next after the Serb conquered 20th-seeded Belgian David Goffin 6-3 6-3.