After dropping the second set, the former World No.1 found herself 4-2 down in the decider before storming home to win 7-6 3-6 6-4.
The win sets up a clash with Italian sixth seed Jasmine Paolini.
Paolini advanced when Ons Jabeur, trailing 4-3 in the opening set, had to retire with a left leg injury.
Osaka, who returned to action in January 2024 after a 15-month break during which she had a baby, said her fitness level was better now than it was in 2021 when she won the most recent of her four Grand Slam titles.
"I feel like I'm better than 2021. You know, COVID really set me back, I'm not going to lie. I was in the house doing nothing," she said.
"But yeah, fitness-wise definitely the best I've been in a couple of years, for sure."
Also on Saturday, world No.1 Aryna Sabalenka reached the last 16 after coming to Miami fresh from a loss in the final at Indian Wells.
Sabalenka, wrapped up the first set 6-1 before Romanian Elena-Gabriela Ruse was forced to retire with a right thigh injury.
Up next for three-times Grand Slam champion will be the winner of Saturday's night match between American defending Miami champion Danielle Collins and Swiss qualifier Rebeka Masarova.
Third seed Coco Gauff also progressed with a 6-2 6-4 win over Greece's Maria Sakkari.