* Williams to meet Italian Errani in last four
* Sharapova into semis for first time, to play Ivanovic (Updates with Ivanovic win, quote, details)
MADRID, May 10 (Reuters) - World number one Serena Williams was given her first serious test at this year's Madrid Open but recovered from a second set mauling to beat Spaniard Anabel Medina Garrigues 6-3 0-6 7-5 in the quarter-finals on Friday.
It was only the seventh time in her career Serena had lost a set to love, the last time being in November 2008 against her sister Venus at the season-ending WTA Championships in Qatar.
The defending champion at the clay event fought back from 4-2 down in the third set to see off the unseeded local favourite, who was cheered on by a partisan crowd at the Magic Box Arena, in two hours and 14 minutes.
Williams, who had not dropped a set in her opening three matches, will meet seventh-seed Sara Errani in the last four, after the Italian swept aside unseeded Russian Ekaterina Makarova 6-4 6-3.
On the other side of the draw, world number two Maria Sharapova comfortably booked a semi-final berth by beating unseeded Estonian Kaia Kanepi 6-2 6-4.
The Russian will meet Serbian former world number one and 16th seed Ana Ivanovic, who dismissed Germany's sixth seed Angelique Kerber 6-3 6-1.
"It was definitely a battle," American Williams told a news conference after her struggle with Medina Garrigues.
"I obviously didn't do much in the second set and I think I gave her a lot confidence to play better. I thought she played really well in the third."
Williams made it 26 wins and only one defeat since the start of last year's claycourt season, but was up against an experienced player on the surface.
The 30-year-old Spaniard has the highest number of claycourt title wins with 10 among active players and stunned the American when taking the second set to love.
"I wasn't really there," Williams said. "I wasn't really in it. My feet weren't moving. I don't know what happened.
"To turn it around I got up earlier on the changeover and started doing high knees and just stretching and doing anything to try to get my intensity back up where it needed to be.
"I definitely want to cut back on my unforced errors. I had a lot today. Also, I went for a lot more today than I have been doing in my past few matches.
"So I think I'm going to go back to the way I have been playing, and being more calm, and not making as many errors as I did today."
French Open champion Sharapova qualified for the semis for the first time in four appearances in Madrid.
"I was just happy to get past the quarter-finals. I feel like I've been stuck in this tournament," the Russian said.
"I faced her (Kanepi) at the French Open where she had really good wins last year, so I know she's capable," Sharapova added of her opponent, who reached the quarter-finals at Roland Garros last year.
"So I was just really determined. I'm happy that I was able to win with that type of scoreline."
Ivanovic reached the last four of a tournament for the first time this year by beating Kerber and is relishing facing Sharapova, who knocked her out at the quarter-final stage in Stuttgart after a three-set marathon.
"It was a really good match in Stuttgart," Ivanovic said. "There are just a few little points I'm going to try to focus on more for tomorrow's match.
"Stuttgart was indoors; here there's a little bit of altitude and it's faster. I think it's going to be very important to focus on the first strike and my serve as well." (Reporting by Mark Elkington, editing by Pritha Sarkar and Ken Ferris)