Sharapova’s ranking of No. 41 in the world forced her to play a first-round match in the tournament she has won twice.
She trailed 4-1 in the first set before holding serve at 4-all. But Osaka held to go up 5-4 and broke Sharapova on a double fault to close out the set.
Ranked 44th in the world, Osaka took a 4-2 lead in the second set. Sharapova broke to tie it at 4-all, before Osaka won the final two games to end the 1½-hour match.
Two American teenagers advanced to the second round.
Amanda Anisimova defeated 94th-ranked Pauline Parmentier 6-2, 6-2 for her first WTA Tour victory. The 16-year-old Anisimova, who earned a wild card into the main draw, is the U.S. Open junior champion.
Caroline Dolehide, a 19-year-old wild card, fired 11 aces in outlasting 78th-ranked Shelby Rogers, 3-6, 7-6 (6), 6-3 in 2½ hours.
In other matches on the first day of the two-week tournament, Belinda Bencic saved a match point in beating Timea Babos, 1-6, 6-1, 7-6 (4), while wild card Eugenie Bouchard lost to qualifier Sachia Vickery, 6-3, 6-4.
Serena Williams will return to the pro tour for the first time in 14 months on Thursday, when she plays a first-round match.