Twice Shanghai Masters champion Roger Federer was far from his best against Spain's Roberto Bautista Agut but did enough to reach the quarter-finals with a 6-3, 2-6, 6-4 win on Thursday.
The top-seeded Swiss, who is fighting to defend the title and his world number two spot, broke in the fourth game and sealed the opening set with a crisp backhand volley.
But Bautista Agut, the 2016 finalist, was back on song in the second set and won four straight games before forcing a decider courtesy a stunning backhand return.
Having lost a set for the first time in eight meetings with Bautista Agut, Federer cut down his errors before breaking in the ninth game en route to his 38th match win of the season.
In the last four the 37-year-old will face eighth-seeded Japanese Kei Nishikori, who knocked out big-serving American Sam Querrey 7-6(7), 6-4.
Wimbledon and U.S. Open champion Novak Djokovic exacted revenge over Italian Marco Cecchinato with a 6-4, 6-0 victory.
The 31-year-old Serb is now unbeaten in 15 matches on the ATP tour and has won 28 of 30 matches since losing to then world number 72 Cecchinato in the French Open quarter-finals in June.
"I was making him play always an extra shot," Djokovic said. "I was aggressive when I needed to be. The second set was perfect, really."
"I wanted to start off well because I know that he battles hard and he makes you deserve every point, win every point."
Seventh-seeded Wimbledon finalist Kevin Anderson awaits Djokovic in the quarter-finals after the South African overcame Greek youngster Stefanos Tsitsipas 6-4, 7-6(1).
Fourth seed Alexander Zverev raced past Australian number one Alex de Minaur 6-1, 6-4 to improve his match record to 48-15 for the season.
With a dominant serve and a mix of clever groundstrokes, Zverev moved just one match win away from qualifying for the ATP Finals for a second consecutive year.
The German will next face 11th-seeded Briton Kyle Edmund, who produced a clinical performance to beat Nicolas Jarry of Chile 7-6(5) 6-3 in 90 minutes.
Garcia, Martins advance to Tianjin quarters
Second seed Caroline Garcia beat Chinese qualifier Zhang Yuxuan 6-3, 6-4 on Thursday to advance to the Tianjin Open quarter-finals.
Facing the 24-year-old local hope for the first time, Garcia dropped her serve in the opening game but rallied to claim the next five games, including a run of 11 points in a row.
The pair exchanged early breaks in the second set but Garcia took a decisive lead at 4-3 and went on to seal victory in 90 minutes.
"It's never easy to play someone you never played before," French number one Garcia said.
"She had nothing to lose, and she was hitting the ball very well, especially from the backhand side."
The 24-year-old will next face sixth seed Petra Martic.
"I played her in Madrid this year," said Garcia, who beat Martic 6-3, 7-5 in the Spanish capital. "She has a good serve and a good forehand, so I'll have to play my best and see what I can do."
Third seed Elise Mertens secured an impressive 6-2, 6-3 victory over Slovakian Jana Cepelova and the Belgian will face Taiwan's Hsieh Su-wei in the last eight.
Briton Katie Boulter recovered from a mid-match blip to put away Czech Barbora Krejcikova 6-3, 1-6, 6-3 and set up a quarter-final against top seed Karolina Pliskova.