(Reuters) - Roger Federer survived a stern examination by American teenager Taylor Fritz in Stuttgart on Thursday to win his first match since withdrawing from the French Open with a back injury.

The Swiss 17-times grand slam champion resumed leading 4-3 in the opening set after rain curtailed play at the Mercedes Cup the previous day and he eventually prevailed 6-4 5-7 6-4.

Fritz, 18, levelled the match when he converted his fourth set point but Federer edged home in the decider to set up a quarter-final against Florian Mayer.

His victory was his 1,071st on the ATP Tour, taking him joint-second on the all-time match wins list with Ivan Lendl.

Jimmy Connors is the overall leader with 1,256 wins.

"It wasn't easy," Federer told the ATP's website.

"(Fritz) served well and I was a little bit cautious, unsure of how to move and questioning my defence.

"These are the things I will need to iron out."

Top seed Federer has been struggling with injuries this season, requiring knee surgery in February and then nursing a back problem throughout the clay court season.

He was encouraged that he was able to get past Fritz with no injury concerns.

"I can take a lot of confidence out of this match. I need to improve a few things, but I served big and I was able to handle three sets over two days, and find some energy at the end of the match. I know I have an extra gear," he said.

There was also a win on Thursday for Austrian third seed Dominic Thiem who made the semi-finals of the French Open last week, losing to Novak Djokovic. On Thursday he beat Australia's Sam Groth 7-6(3) 7-6(2).

(Reporting by Martyn Herman; editing by Clare Lovell)