Madrid: Roger Federer rallied to beat Milos Raonic 4-6, 7-5, 7-6 (4) at the Madrid Open to narrowly avoid his earliest tournament exit in two years.

Federer hasn't been eliminated from a tournament in the second round since the 2010 Rome Masters, and the 16-time Grand Slam champion had to call on his wealth of experience and shotmaking abilities to survive an early scare against the 23rd-ranked Canadian player.

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

Raonic also stretched Federer to three sets in their only other meeting at Indian Wells earlier this season, where Federer also rallied to win.

Raonic 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.

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.

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.

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.

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 quarterfinals 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.