Serena Williams battled her way through to the semi-finals of the Madrid Open with a hard-fought, three-set victory over local favourite Anabel Medina Garrigues 6-3 0-6 7-5.
Williams had cruised through to the last eight without dropping a set but was handed a real test against the wildcard at the Caja Magica.
With the scores at 3-4 in the opener, world No 1 and defending champion Williams stepped up a gear to break her Spanish opponent before closing out the opening set.
However, against all expectations, 63rd-ranked Medina Garrigues wiped the floor against the 15-time Grand Slam champion in the second set, breaking her serve three times.
The 30-year-old relaxed and played Williams off the court as she inflicted the first 'bagel' set on her opponent since 2008.
Williams appeared to have regained control early in the third though as she got off to a 2-0 lead, but Garrigues came roaring back again and broke in successive games to move ahead 4-2.
The Spaniard faltered as she gifted the break straight back before the next three games went with serve.
American Williams made the decisive break when she pounced on a weak second serve to power a backhand down the line and go 6-5 in front before holding to love to set up a semi-final meeting with Sara Errani after she beat Ekaterina Makarova 6-4 6-3.
"It was definitely a battle," said Williams, who racked up nearly 50 unforced errors. "I obviously didn't do much in the second set and gave her confidence to play better.
"To change it I got up early (before the third set) and did some high knees, some stretching, anything I could to get my intensity back up to where it needs to be."
Victory for Williams means she extends her winning run to 17 matches and remains on course for a meeting with second-seed Maria Sharapova in Saturday's final.