After the 10th-ranked Azarenka, who celebrated her 25th birthday, saved three match points to force to tie it 6-6, Williams won the first five points in the tiebreaker.
Azarenka's second serve was the biggest difference between the two hard-hitting players. She won just 32 percent of her second serves, handing Williams a significant advantage.
Williams, who reached her third quarterfinal of the season, will face eighth-seeded Andrea Petkovic on Friday.
Williams, in her 12th career appearance at Stanford, reached her 10th quarterfinal. She has won the twice and finished second five times.
Azarenka won the event in 2010 and has been eliminated in the second round in her last two appearances.
Fifth-seeded Ana Ivanovic also advanced, beating qualifier Carol Zhao 6-1, 6-1.
The 11th-ranked Serb, looking for her fourth title of the year, will face top-ranked Serena Williams on Friday.
Zhao, a sophomore All-American at Stanford, appeared in her second WTA Tour event and gained her first career win at the level Tuesday when Yanina Wickmeyer retired because of a viral infection.
Ivanovic, a former No. 1, had three aces and won 75 percent of her first-serve points.
In other matches, third-seeded Angelique Kerber beat Coco Vandeweghe, 7-6(4), 0-6, 6-2, and Garbine Muguruza topped Daniela Hantuchova, 6-4, 6-4.
"It will be a tough challenge but a good test to see where I need to work," Ivanovic said. "It's a different part of the season and a different kind of tournament."