Williams won in straight sets, beating Japanese contender Kurumi Nara 6-3, 6-3 to advance into the round of 32. Osaka lost her first set 6-4 to Victoria Azarenka, before winning 7-5, 6-3 down the stretch.
Williams had 36 winners and did not face a break point in the victory.
"I think I was just too nervous in my first round match," Williams told the Tennis Channel. "... I knew I could play better. I knew I couldn't go down. I've been practicing really, really well and it just didn't manifest itself in that first round."
Osaka's close call came after she survived a three-set clash against Anna Karolina Schmiedlova in the first round. Williams also took three sets to win her first round match against Vitalia Diatchenko on Monday at Roland-Garros.
Osaka's victory took 2:50, while Williams was off of the court in 1:07. Osaka was down 4-2 in the second set, following her first set loss to Azarenka before climbing back into her second round match. Williams trailed just once in her match.
"I think this match was equal parts mental and physical. Maybe more mental," Osaka told reporters.
"The first set was, I got rolled. I made a little bit of a comeback in the end of the first set, but technically, she kind of killed me in the first set, and I just kept trying to find a way to stay positive."
Williams faces Sofia Kenin and Osaka battles Katerina Siniakova in the round of 32 on Saturday in Paris. Monica Puig, Irina-Camelia Begu, Ashleigh Barty, Amanda Anisimova, Iga Swiatek, Aliona Boslova Zadoinov and Ekaterina Alexandrova were among the other women to advance to the third round on Thursday morning at Roland-Garros.