Roger Federer overcame a two-set deficit Friday at Wimbledon to avoid his earliest Grand Slam exit since 2004.

The six-time champion found himself two points from defeat on six occasions but survived a tense fourth-set tiebreaker and beat Julien Benneteau in the third round, 4-6, 6-7 (3), 6-2, 7-6 (6), 6-1.

"It was a tough match," Federer said. "Oh my God, it was brutal. Obviously, a bit of luck, maybe, on my side. Who knows? But I tried hard. I fought 'til the very end."

Federer avoided the fate that befell nemesis Rafael Nadal 24 hours earlier on the same Centre Court. Nadal, a two-time champion, made his quickest exit from a major since 2005 when No. 100-ranked Lukas Rosol beat him in five sets Thursday.

Benneteau had won his past four five-set matches, but this time he was the wearier player at the end, twice requiring thigh massages from a trainer for cramps during the fifth set. Federer cracked a forehand return winner into the corner to break for a 3-1 lead and pulled away from there.

A hobbling Benneteau appeared in tears before the final point, and he dumped his last shot in the net. Fans roared as a grinning Federer gave them a triumphant wave.

"He proved he is great. The greatest," Benneteau said. "Mentally he's a rock. He's two sets down, and he doesn't show anything."

Federer also erased a two-set deficit to beat Juan Martin del Potro in this month's quarterfinals at the French Open. He has mounted eight comebacks from down 0-2 in his career.

"The thing, when you're down two sets to love, is to stay calm, even though it's hard, because people are freaking out, people are worried for you," Federer said. "You don't have, obviously, many lives left out there. You just try to play tough and focus point for point. Sounds so boring, but it's the right thing to do out there."

The No. 3-seeded Federer seeks to match Pete Sampras' modern record of seven Wimbledon championships. He has been stalled for 2½ years at a record 16 Grand Slam titles, but Nadal's departure improves his chances next week.

Federer has reached at least the quarterfinals at a record 32 consecutive major tournaments.

Top-ranked Novak Djokovic earlier mounted a more modest comeback to beat Radek Stepanek 4-6, 6-2, 6-2, 6-2.

When a drizzle delayed the start of the third round, tournament officials decided Djokovic's match should be played inside. An odd spectacle ensued: The roof closed as the sun came out and outside court covers came off.

"I was a little bit surprised, when I saw sunshine, that the roof is closed," the defending champion said. "Obviously they're relying on a forecast that I don't think is very reliable here. But OK."

Djokovic missed opportunities to seize an early lead, failing to convert his first five break-point chances before he lost serve at love to drop the opening set. But he dominated from there, breaking in the first game in each of the final three sets.

Also advancing to the second week was top-ranked Maria Sharapova. She rallied from a break down in the second set to beat Hsieh Su-wei 6-1, 6-4.

American Sam Querrey hit the last of his 21 aces on match point and beat No. 21-seeded Milos Raonic, 6-7 (3), 7-6 (7), 7-6 (8), 6-4. That second-round match had been suspended in the third set Thursday because of rain.

Kim Clijsters led 6-3, 4-3 when No. 12 Vera Zvonareva retired with a respiratory infection. The unseeded Clijsters, who plans to retire after the U.S. Open, is a four-time Grand Slam seeking her first berth in a Wimbledon final.

"It's a pleasure to be a part of the second week of a Grand Slam, especially at Wimbledon," she said.

Americans Sloane Stephens and Christina McHale were eliminated in the third round. The 19-year-old Sloane Stephens was beaten by Sabine Lisicki 7-6 (5), 1-6, 6-2, and the No. 28-seeded McHale lost to No. 8 Angelique Kerber 6-2, 6-3.

No. 3 Agnieszka Radwanska defeated Britain's Heather Watson under the roof, 6-0, 6-2.

Because of the daylong rain threat, Federer's match was played with the roof closed. The No. 29-seeded Benneteau broke in the ninth game to seize the lead, and rallied from a break down in the second set, taking advantage of a blown overhead by Federer on a key point to reach 4-all.

In the next game, Benneteau cracked a return winner, and the Frenchman shouted, "Allez!"

Federer, who speaks six languages, responded with a service winner and also hollered, "Allez!"

Benneteau wobbled serving at 5-6 in the second set, double-faulting twice and blowing an overhead. The score went to deuce seven times, but he managed to hold with the help of several big serves.

"He played so well," Federer said. "He was making me doubt, obviously, for most of the match. That's a credit to him. He played amazing, I thought."

Benneteau whacked two aces in the tiebreaker, and at that point nothing seemed to be going Federer's way. He even went 0 for 4 in the set requesting relay reviews.

The comeback began quickly, with Federer racing to a 4-love lead in the third set, but the fourth set was more difficult. Benneteau was two points from an upset for the sixth and final time at 6-all in the tiebreaker, but he hit a backhand long and a forehand into the net.

Federer skipped to his chair, relieved to be still in contention at Wimbledon.