The 2018 champion, seeded fourth, won 6-3 6-7 (4-7) 6-2 against the 18-year-old Ukrainian on Arthur Ashe Stadium in New York.
Japan's Osaka, 22, had to save five break points to avoid going 3-1 down in the decider but then managed to win the last five games at Flushing Meadows.
She will play 14th seed Anett Kontaveit next.
The world number nine is carrying a hamstring injury that forced her out of last week's Western and Southern Open final and wore heavy strapping on her left thigh.
Osaka, who has been speaking out against racism in the United States, came on to court at Flushing Meadows wearing a face mask bearing the name of Ahmaud Arbery, a black man who was shot dead while jogging in Georgia in February.
She has said she will wear a mask with a different name for each match she plays in New York.
Elsewhere in the women's draw, German 2016 champion Angelique Kerber beat Ann Li 6-3 6-4 and will now play American 28th seed Jennifer Brady, who saw off France's Caroline Garcia 6-3 6-3.
Garcia had knocked out top seed Karolina Pliskova in the previous round.
Czech sixth seed Petra Kvitova breezed past American Jessica Pegula 6-4, 6-3 to set up a last-16 encounter with Shelby Rogers, also of the United States.
Petra Martic won 6-3 6-3 against Russia's Varvara Gracheva and the Croatian eighth seed next faces Kazakh 23rd seed Yulia Putintseva.