The fifth seed was sluggish throughout and despite a brief revival in the second set, stuttered to a 4-6 7-6(5) 3-6 defeat by the Frenchman.
The loss means that Federer is still not guaranteed a place at next month’s season-ending ATP World Tour Finals.
The Swiss world No7 is currently seventh in the race to qualify for the London tournament, but following Andy Murray’s withdrawal, the next spot will go to the player in ninth.
Speaking before the Shanghai tournament, Federer outlined reaching the World Tour Finals as his top objective.
“It was the goal at the beginning of the season to qualify for [London],” said Federer.
“I consider it the absolute best-of-the-best tournament out there, so I want to be part of that.
“It’s extra motivation for me to play well and be part of that great tournament.”
Elsewhere in Shanghai, there were wins for Florian Mayer and Jo-Wilfried Tsonga, while Juan Martin del Potro was handed a place in the fourth round after Tommy Haas withdrew with injury.
MORE: The latest football news
MORE: The latest tennis news