Williams, who rolled back the years by beating world number two Azarenka on Tuesday, was made to work harder by Romanian 13th seed Halep in the last 16.
The veteran American lost the first set and was a break down on three occasions in the second before eventually forcing a decider, where she trailed 2-0 but bounced back again to record a 4-6 7-5 6-3 win in two hours and 25 minutes.
She will next face Eugenie Bouchard, who produced the shock of the day by comfortably defeating sixth seed and former world number one Jelena Jankovic in straight sets.
Canadian Bouchard, who came back from 5-7 3-5 down to stun American ninth seed Sloane Stephens last time out, won nine of the last 11 games in her 7-5 6-2 success against her Serbian opponent.
There were no such upsets for Agnieszka Radwanska, Caroline Wozniacki and Angelique Kerber, the highest three seeds left in the draw, all of whom advanced to the last eight with straight sets wins.
Polish second seed Radwanska, who is looking for her fourth title of the year and second in two weeks after triumphing in the Korea Open last Sunday, saw off 16th seed Dominika Cibulkova 6-3 6-4.
Wozniacki looked impressive in her demolition of Slovakia's Magdalena Rybarikova. The Danish fourth seed, champion in 2010, cruised to a 6-1 6-1 triumph in 88 minutes.
German fifth seed Kerber set up an intriguing showdown with Radwanska after defeating Serbia's former French Open champion Ana Ivanovic 6-4 6-2, while Australia's Samantha Stosur, seeded 12th, tumbled to a 6-4 6-4 defeat against Lucie Safarova of the Czech Republic.