MADRID, Spain - Canada's Milos Raonic pushed Roger Federer to the brink of elimination in the second round of the Madrid Open.

But the hard-hitting native of Thornhill, Ont., couldn't complete the upset as the third-seeded Federer survived two tiebreakers en route to a 4-6, 7-5, 7-6 (4) win Wednesday.

Raonic did what he could against the Swiss star, firing 21 aces in a match that lasted two hours 13 minutes. But he also missed plenty of opportunities by converting just one of eight break point chances.

The 21-year-old last lost to Federer in three sets at the third round at Indian Wells in March, but had hoped to build on his win over No. 4 Andy Murray two weeks ago in Barcelona.

"I felt I played really well the whole time doing what I wanted to do," said Raonic. "I was dictating on my serve. I had a lot of looks on his serve, I came up a bit short today though.

"I was there the whole match and doing the right things. It was good, and I'll probably be more happy in a few days about the outcome."

Federer, who hasn't been eliminated from a tournament in the second round since the 2010 Rome Masters, will face France's Richard Gasquet in the third round.

Federer recalled a past era when describing a fast-paced match full of power and passing shots.

"These are some of the fastest courts on tour, I expected that a few shots would decide the match, that's what it was like back in the days of (Pete) Sampras, (Boris) Becker and (Stefan) Edberg," Federer said. "That's the way it was tonight."

Rafael Nadal had an easier time in his first match on the blue clay as he beat Nikolay Davydenko 6-2, 6-2.

Defending women's champion Petra Kvitova lost to Lucie Hradecka 6-4, 6-3 while top-seeded Victoria Azarenka beat Ana Ivanovic 6-4, 6-4.

Raonic, ranked a career-high 23rd, overpowered Federer's attempts to serve-and-volley early as he hit perfect passing shots whenever the Swiss star came forward. Raonic won 12 straight points to close out the first set, earning the decisive break in the ninth game.

Federer was on the back foot again to start the second, but the Swiss player's serve bailed him out repeatedly, helping him save all four break points he faced in the set.

"There is a lot to do in my game to beat him, it was the difference of a point or two," said Raonic. "I took care of my serve and didn't face too many difficult moments. If I want to be in this situation week in, week out, I'll have to improve my return game."

Federer secured the break he needed in the 11th game by stretching Raonic wide to send a shot into the net, and then clinched the set with a soft drop shot.

"I thought I could take it to him by serving and volleying and it worked a bit," Federer said. "I definitely started to get a better read on his serve and to get into more baseline rallies, make him hit more shots on his own serve."

Both players held serve in the decider to force the tiebreaker, where Federer led 4-1 before a number of erratic shots from the Swiss player allowed Raonic to cut it to 5-4.

But Raonic unleashed a wild forehand long to give Federer match point, and the third-ranked Swiss stroked a sublime crosscourt forehand to clinch the victory.

"If I can get things going my way, I can build confidence," said Raonic. "Today I stepped on court believing I could win, and left the court knowing I could have won."

Unlike Federer, Nadal thrived on the surface that he criticized this week as soft and slippery, hitting six aces.

"I played much better than I expect," Nadal said. "The (blue) court ... doesn't make you feel comfortable. It's difficult, hard to attack and come back to defend. You just have to try and adapt."

Nadal, who broke his Russian opponent four times to advance to the third round, will next meet Fernando Verdasco. The Spaniard defeated Alejandro Falla of Colombia 6-7 (4), 6-4, 6-4.

Also, Marin Cilic beat John Isner 7-6 (4), 7-6 (3) and fifth-seeded David Ferrer advanced by beating Radek Stepanek 7-6 (4), 6-2.

"It has nothing to do with the courts, I just didn't play well," said Isner, who praised his Croatian opponent. "He has played better and he deserves to win."

Other men's winners on Wednesday included Juan Martin del Potro, Stanislas Wawrinka of Switzerland, Alexandr Dolgopolov of Russia and French players Gilles Simon, Gael Monfils and Richard Gasquet.

The third-seeded Kvitova struggled with her serve against Hradecka. Kvitova was broken five times by Hradecka of Czeck republic, who will face Ekaterina Makarova in the third round. Makarova beat Maria Kirilenko of Russia 6-4, 6-4 to advance.

Li Na of China and Samantha Stosur of Australia both reached the quarter-finals along with Agnieszka Radwanska, who routed Sara Errani 6-0, 6-1 and ended the Italian's 16-match winning streak.

Errani failed to convert any of her eight break points as she showed little of the consistent play that carried her to three straight titles this season.

Radwanska will next face Roberta Vinci following her 6-1, 6-2 victory over Yanina Wickmayer of Belgium.