Unfortunately, Williams lasted just one more game, looked weak and dizzy, and retired 0-1 down in the second set.
After a first set in which she had led 3-0, Williams had a lengthy conversation with the trainer and doctor but no medical timeout was taken.
Serena Williams' most recent campaign ended in retirement. It was a bit cooler than the norm for March here, but not fur coat weather.
"I felt that maybe she wasn't feeling well", said Muguruza. "I will focus on getting better and start preparing for Miami", she said, referencing next week's Miami Open. She emerged for the second set but it was short lived.
Williams' illness withdrawal was unfortunate for the fans, because it had the best chance of Sunday's marquee offerings to be a real battle.More news: 'Game of Thrones' final season episode lengths revealed
Williams, a two-time champion of the event, trailed Garbine Muguruza before retiring due to a viral illness.
The last two of those were in finals, with Williams beating the Spaniard for the Wimbledon title in 2015 and Muguruza taking the 2016 French Open crown.
Osaka won her first career title at Indian Wells a year ago, propelling her to a career-best year in which she defeated Serena Williams for the US Open title. Williams rallied from early breaks down in both sets to win. "That's what I am looking for", WTA quoted Muguruza as saying. When I play them, I am excited.
"I wish I'm going to see her soon and [she's] feeling better".More news: Did You Notice This Strange Blinking Pixel On Galaxy S10?
Muguruza is only the second Spanish woman to become No. 1 in the world, after Arantxa Sanchez Vicario.
"I think she started playing well, right away with her serve, with her shots, being very dominating", Muguruza said after the match. "My mindset was just to keep trying to get my feet moving and stay pumped up and positive". "That helps me get that feeling".
"It was really hard against her because I never played against her", said Halep.
Muguruza will now face either Kiki Bertens or Johanna Konta in the round of 16.
Now Bertens managed to maintain her aggressive tennis while keeping her error count down compared with the Briton's 42, and sealed her first fourth-round run in the tournament, 6-4, after breaking in the ninth game.More news: Check your smoke detectors as Daylight Saving Time kicks in