Stephens lost her first three matches against Azarenka, which all came in the Australian Open from 2013-15
American Sloane Stephens recorded her fourth successive win over former world number one Victoria Azarenka to advance to the round of 16 at the Madrid Open.
The 26-year-old world number eight was broken twice as Azarenka, now ranked 52, took the match to a deciding set.
Belarusian Azarenka, 29, spurned two break points at 1-1 and Stephens won 6-4 2-6 6-2 in two hours, six minutes.
Stephens will face the winner of Tuesday's match between China's Zheng Saisai and Alize Cornet of France.
Seventh seed Kiki Bertens and 12th-ranked Anastasija Sevastova recorded straight-set victories over Jelena Ostapenko and Mihaela Buzarnescu respectively.