The 12th-ranked Stephens won just two of the first 14 points and later dropped 5-2 behind against Petkovic, but the American saved three set points before taking the opener in a tiebreaker.
"I let out some screams which I normally don't do," Stephens said about her slow start. "I am just happy to get through."
Stephens went 3-1 up in the second set before Petkovic reeled off 10 straight points to turn it around.
Stephens managed an early break in the decider and the Australian Open semifinalist closed out the victory on her third match point.
Stephens next plays Stefanie Voegele of Switzerland, who rallied to defeat Karin Knapp of Italy 4-6, 6-2, 7-5 to advance to her first quarterfinals since April.
Earlier, Dominika Cibulkova of Slovakia routed Katarzyna Piter of Poland 6-0, 6-1 in less than 53 minutes. Piter, playing in her first main draw of the year, broke the seventh-seeded Cibulkova in the second set for her only game.
In her fourth quarterfinal of the season, Cibulkova will take on two-time former champion Ana Ivanovic.