Roger Federer's chances of qualifying for the ATP Tour Finals took a hit Thursday when he lost in three sets to Gael Monfils at the Shanghai Masters, the latest early round loss for the 17-time Grand Slam champion.

Monfils beat the former No. 1-ranked Federer 6-4, 6-7 (5), 6-3 in the third round.

Defending champion Novak Djokovic and top-ranked Rafael Nadal moved into the quarterfinals with straight-set wins.

Two of the tournament's other top seeded players were ousted: No. 3 David Ferrer lost to Florian Mayer 6-4, 6-3, and No. 4 Tomas Berdych was upset by Nicolas Almagro 6-7 (6), 6-3, 7-6 (4).

Federer, who has slipped to No. 7 in the rankings, was playing for the first time since losing in the fourth round of the U.S. Open. He needed a strong showing in Shanghai to secure a berth in the elite season-ending ATP Tour Finals in London — a tournament he played every year since 2002.

Federer is currently seventh in the standings, with only a slight lead over several other players vying to get into the eight-man field in London. He plans to play in Basel and Paris in hopes of making it into the Nov. 4-11 tournament.

Federer fell to a player ranked outside the top 40 for the fourth time in his last six matches. He came into the match with a 6-1 record against Monfils, who recently returned to the tour after an injury layoff.

Federer remained upbeat despite the loss — and his subsequent defeat in doubles with Chinese partner Zhang Ze. He said the most important thing was not to worry about every setback.

"It's pretty simple: You just keep on working hard, make sure that you get back on winning ways, then you become confident again, sort of get there," Federer said.

"Monfils is a quality player, like some others," he said. "I lost some other matches this year because I couldn't really perform at 100 percent. Probably shouldn't have played. But I don't really care having to explain some losses from time to time."

Jo-Wilfried Tsonga, Juan Martin del Potro and Stanislas Wawrinka also advanced to the quarterfinals, strengthening their bids to qualify for the ATP Finals.

Tsonga, one of several players chasing Federer, defeated Japan's Kei Nishikori, 7-6 (5), 6-0, and del Potro moved through when Tommy Haas withdrew before their match with a back injury.

Wawrinka advanced with a 7-6 (2), 6-4 win over Canadian Milos Raonic, one of the strongest players coming into Shanghai after reaching back-to-back finals in Japan and Thailand and winning one title.

As has been his problem in recent months, Federer struggled to find consistency. He had 36 unforced errors, with many coming at critical points in the match. Still, he looked to have a chance to pull it out after rallying from a break down in the second set.

On Monfils' serve in the next game, Federer hit an overhead smash to get a break point and then converted with a deeply angled crosscourt winner, pumping his fist as the pro-Federer crowd roared.

But Federer was broken again early in the third set and couldn't muster another comeback. He had two more break chances in the seventh game, but couldn't convert either, even with Monfils looking spent, bending over to catch his breath after long rallies.

Monfils, who's ranked 42nd but has been as high as No. 7, said even though Federer has not been as dominant as he used to be, with the likes of Djokovic, Nadal and Andy Murray contending for the majors, he's still no pushover.

"A lot of people say, like, it's not the same Rog because he got two other great players with him, Novak and Rafa. A third one plays also very good, Andy," he said. "But when he's on the court, he's still Roger. He can rip it from anywhere. He can do stuff that not many players can do."

Monfils did notice, however, a slight dip in Federer's game.

"I think he miss a little bit more than he used to," he said. "I know he will try and go for his shot, but maybe he is a bit less confident."

Djokovic, who faces Monfils next, said although Federer's form has dropped this season, it would be a mistake to write him off.

"He's 17-time Grand Slam winner, one of the best players in the history of the game. If he says he's going to play better, work better, it's definitely worth listening if he says it that way," he said.