Williams had taken a 3-0 lead in the first set before losing the next seven games. She walked to the chair after the first game of the second set and sat down, breathing heavily. After a discussion with supervisor Donna Kelso the American retired.
Tournament officials said the former world number one was suffering from a viral illness and Williams later confirmed she had been feeling ill ahead of the third-round tie.
'She is a billion-dollar girl' - How Raducanu has the world at her feet
"Before the match, I did not feel great, and then it just got worse with every second; extreme dizziness and extreme fatigue," Williams said in a statement.
By the score, it might have looked like I started well, but I was not feeling at all well physically. I will focus on getting better and start preparing for Miami.
Williams, 37, had shown signs of fatigue during the first set and after it was completed she called for a trainer and following a lengthy conversation returned to the court.
Muguruza said it felt like a hollow victory.
"I felt that maybe she wasn't feeling well," she said.
"It's really a weird feeling, because I don't feel like I won the match point and (got the) 'well done, ... good match'.
It was just like, 'man, we'll play next time.
Williams, who has won 23 Grand Slam singles titles, gave birth to a daughter in 2017 and returned to play last year.
She is currently ranked 10th in the world and was playing in her first tournament since the Australian Open in January.
She defeated Victoria Azarenka 7-5 6-3 in her first match at Indian Wells on Friday.
Opinion: No multiple major winners again, but Barty’s 2021 season should be given more respect
US Open
'The younger generation has taken over' - Becker hails 'Dame Emma Raducanu'
16/09/2021 AT 14:32