The top-ranked Williams needed 1 hour, 57 minutes to mount a second-set comeback and scrape her way to a 2-6, 6-4, 6-2 defeat of Slovak Dominika Cibulkova and a berth in the Miami quarterfinals.
Williams trailed 1-4 in the middle frame but recovered to sweep its final five games, later grabbing the advantage by breaking serve at love for a 2-1 lead in the final stanza.
She fired 14 aces, including one to end the match.
Williams drew Li Na as a quarterfinal opponent after the fifth-seeded Chinese star advanced with a 7-6 (8-6), 6-2 victory over Spaniard Garbine Muguruza.
Also Monday, third-seeded Sharapova, coming off a win at Indian Wells, disposed of 21st-seeded Czech Klara Zakopalova 6-2, 6-2 to reach the quarterfinals.
Elsewhere, No. 4 seed and defending champion Agnieszka Radwanska gained the quarters with a 4-6, 6-2, 6-0 comeback win over 16th-seeded American Sloane Stephens.
No. 30 Kirsten Flipkens of Belgium also moved on, rallying over Croat Ajla Tomljanovic 6-7 (6-8), 6-4, 6-3.
Celebrity Breakups and divorces of 2014 [PHOTOS]