A pumped-up Osaka went all out in an ultra-attacking start and took an early break as Muguruza lost serve for just the second time in the tournament.
But a series of unforced errors allowed the composed Spaniard, who nailed 86 percent of her first serves, to level the score before she took a decisive break in the ninth game.
She again broke Osaka early in the opening game of the second with a superb lob winner.
But the 2019 Australian Open champion Osaka settled, broke back in the fourth game and slowly wore down Muguruza to level the match.
The see-saw contest continued in a tense decider with Osaka unable to convert a break point in the fourth game only to subsequently drop her serve and slam her racquet to the ground in frustration.
The Japanese fought back from the brink of defeat to clinch her spot in the quarters. The third seed was on the verge of elimination at 3-5, 15-40 on her serve in the third set before rattling off four points in a row.
She then twice broke the serve of the two-time Grand Slam winner Muguruza to prevail 4-6, 6-4, 7-5 in one hour and 55 minutes of gripping action on an empty Rod Laver Arena, devoid of fans for the second day because of coronavirus restrictions.
“I felt like I was intimidated because she was playing so well,” said Osaka, who hit 40 winners but made 36 unforced errors.
“On the stressful points, I had to play within myself.
Osaka will face Taiwanese veteran Hsieh Su-wei, who qualified for her first Grand Slam quarter-final after 16 years of trying to become the oldest player to make a last-eight debut in the Open Era.
The 35-year-old overwhelmed 19th seed Czech Marketa Vondrousova 6-4, 6-2, a player 14 years her junior, in the Australian Open fourth round on a Margaret Court Arena devoid of fans to witness her feat.
“I’m not looking forward to it, they are always long, tough matches,” said Osaka who sports a 3-1 record over the 35-year-old, who earlier made history by becoming the oldest player to make a last-eight debut in the Open Era.
Osaka and Muguruza, last year’s Australian Open runner-up, have five Grand Slam titles between them but surprisingly had never met on court before.
Muguruza had been showing the form that saw her top-ranked in 2017 and she proved a formidable challenge for Osaka, widely deemed a title favourite at Melbourne Park.
(With inputs from AFP)