Reigning US and Australian Open champion Osaka needed more than two hours to outlast Aliaksandra Sasnovich 7-6 (7/3), 2-6, 6-2.
The Japanese star will next face a third-round match against Taiwan's Hsieh Su-Wei, who defeated American Jennifer Brady 7-6 (11/9) 6-3.
Osaka finally scored a win here at the US Open warm-up after losing in the first round a year ago.
"I was just trying to have fun," Osaka said. "In the second set I was taking myself too seriously and was down on myself.
"Now I just want to have fun and enjoy it. That's what I'm supposed to do."
Serena's US Open plans upended as injury hands Andreescu Toronto crown
Osaka advanced with eight aces, 24 winners and breaks on four of five chances against an opponent who was treated on her right knee several times.
Australia's Barty, 23, won the battle of former number one players in just over 90 minutes. The reigning Roland Garros champion beat five-time Grand Slam winner Sharapova, who was Cincinnati champion in 2011, for the second time this season after a win at the Australian Open.
It was Barty's 40th victory of 2019 and she goes on to face Estonia's Anett Kontaveit, who beat Polish teenager Iga Swiatek 6-4, 7-6 (7/2).
Barty said she remained focused after last week's opening defeat in Toronto.
"It was certainly no panic sessions after last week. I knew I was a little bit underdone going into Toronto and certainly had no worries or concerns there," Barty said.
"I've been striking the ball really well over the last seven or eight days. I found my groove a little bit more. It took a little bit to adjust to conditions, but it was easy for me to swing out at the start."
Barty fired 18 winners, breaking Sharapova four times as the Russian made 31 unforced errors.
Federer, Djokovic advance as Serena pulls out in Cincinnati
Fourth-seeded Halep took a late break in the penultimate game of the final set to beat Russian Ekaterina Alexandrova 3-6, 7-5, 6-4 after two hours on court.
The Romanian has finished runner-up in Cincinnati three times, last reaching the final a year ago against Kiki Bertens.
In the next round, the 27-year-old, who retired injured from her Toronto quarter-final against Czech qualifier Marie Bouzkova last week, will face American Madison Keys, a 6-4, 6-1 winner over Russia's Daria Kasatkina.
"It was a very, very tough match," Halep said. "She played well, hitting the ball very strong. "Mentally, it was tough to return for me at the start after playing injured last week.
"But I didn't have pain, which is good. It took time to get a rhythm and then do something on court."
World number three Karolina Pliskova beat China's Wang Yafan 6-1, 6-3, while seventh seed Elina Svitolina, a semi-finalist four years ago, advanced past Belgian Elise Mertens 6-4, 6-1.
In the men's draw, fifth seed Stefanos Tsitsipas saved three match points but still lost to Germany's Jan-Lennard Struff 6-4, 6-7 (5/7), 7-6 (8/6).
Kei Nishikori went out to fellow Japanese Yoshihito Nishioka 7-6 (7/2), 6-4. Sixth seed Nishikori has still never advanced beyond the third round in Cincinnati.
Alexander Zverev, seeded seventh, remained winless in his Cincinnati career after losing 6-7 (4/7), 6-2, 6-4 to 19-year-old Serb Miomir Kecmanovic. The German struck an unbelievable 20 double-faults in defeat.
Ninth seed Daniil Medvedev, losing finalist to Rafael Nadal in Montreal last weekend, eased past Benoit Paire 7-6 (7/2), 6-1 and will next face Struff.
France's Richard Gasquet, who ended Andy Murray's comeback singles tournament in the first round, saw off Argentinian Federico Delbonis 7-5, 7-6 (7/1).
Australian Alex de Minaur defeated American Reilly Opelka 7-6 (7/3), 6-4 to set up a third-round tie with Nishioka.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ