Eight-time Grand Slam winner Williams looked rusty early on
Serena Williams was given a scare by 15-year-old Michelle Larcher de Brito before winning their second-round match at the Bank of the West Classic.
The American top seed dropped the first set against the Portuguese qualifier before winning 4-6 6-3 6-2.
Williams made eight unforced errors in the initial 12 points.
"It's definitely encouraging to know I can bounce back - I haven't been down a set for a while," she said. "It's the kind of practice I need."
Playing her first match since losing the Wimbledon final to sister Venus, she sprayed her typically reliable groundstrokes long and wide.
She hit ball after ball into the bottom of the net and regularly missed first serves. Her father, Richard, briefly left his seat in a corner box after watching his daughter struggle.
The gutsy Larcher de Brito, ranked 226 in the world, pumped her fist on both her own winners and Williams' unforced errors and was the aggressor until her experienced opponent woke up in the second set.
"I started off really well. I think I played pretty good throughout the whole match," Larcher de Brito said.
"I kind of slowed down a little bit. I came through qualifying a little tired, but she played a great game - she is Serena Williams."
Larcher de Brito is the seventh youngest player to win a Tour match
Williams, 26, will play in the quarter-finals on Friday against the winner of Thursday's second-round match between Russia's Alisa Kleybanova and Swiss fifth seed Patty Schnyder.
Also on Wednesday, Japan's Ai Sugiyama ousted fourth-seeded Daniela Hantuchova of Slovakia 6-3 6-1 to advance to the last eight.
The unseeded Sugiyama went 3-0 down in the first set but won the next nine games, before Hantuchova held serve to make it 3-1 in the second set.
Hantuchova has been nursing a stress fracture in her right heel since May, and Wimbledon was her first tournament since April.
Sugiyama will face Slovakia's Dominika Cibulkova, a 6-2 6-3 second-round winner over Ukraine's Kateryna Bondarenko.
Russian second seed Anna Chakvetadze beat Israeli Shahar Peer 6-3 6-4 and plays the winner of Thursday's second-round match between French sixth seed Marion Bartoli and Britain's Anne Keothavong.
Lindsay Davenport will miss next week's Los Angeles Classic with the same knee injury that saw her withdraw from this week's WTA Tour event. She picked up the problem in practice at Wimbledon and had to withdraw after winning her first-round match.