The world number three and 17-times grand slam champion was made to work hard before battling through to the last eight with a 6-4 4-6 6-4 win.
Federer, who has reached the final in Basel every year since 2006, will next face Belgium's David Goffin, who he beat to clinch the title in Switzerland last year.
The 34-year-old top seed claimed the first set after breaking in the fifth game, but dumped a backhand into the net when serving to stay in the second at 4-5.
Federer broke again in the ninth game of the decider and served out the match, having clocked up 13 aces and won 87 percent of first-serve points.
Fifth seed and 11th-ranked Richard Gasquet kept alive his hopes of reaching the ATP Tour Finals by beating Dominic Thiem 7-6(1) 6-4.
Gasquet, who next faces giant Croat Ivo Karlovic, must win titles in Basel and Paris in early November to reach the season-ender.
Seventh-seeded Croat Marin Cilic will face Rafa Nadal in the last eight after beating Russian Teymuraz Gabashvili 6-3 6-1 in 75 minutes.
(Reporting by Toby Davis; editing by Ed Osmond)
Share
