"It's really a weird feeling because I don't feel like I won the match point and, 'Well done, you know, good match, '" Muguruza said after the match, according to the WTA's official site.
Still seeking her first tournament title since returning in 2018 from a long layoff that included a hard childbirth, the 37-year-old Williams showed excellent form at the start of Sunday's match.
Williams started the match well against Muguruza and lead 3-0.
"We've played many times and it's always super-tough, super-exciting", said Muguruza, like Williams a former world number one.
Muguruza reeled off six successive games to take the first set but Williams' mobility was well short of her best, and her retirement seemed inevitable at the changeover.
However, Williams - who entered the tournament as the 10th seed - was not moving freely and Muguruza battled back with a series of stunning groundstrokes of her own.
She is now ranked 10th in the world.
"When I was leading the match, she played without fear, I felt like she was playing much better in those games", Halep said.
She retired after losing the first game.
Sixth-seeded Elina Svitolina also advanced, holding of Australian Daria Gavrilova 7-5, 6-4.
Two seeded women lost: No. 11 Anastasija Sevastova, who retired trailing 5-0 in the first set against No. 21 Anett Kontaveit, and No. 15 Julia Goerges, who lost to Mona Barthel 7-5, 1-6, 6-4.