Between coughs at his postmatch press conference, Del Potro said: "It wasn't easy to play for me today, I did what I can". "I wasn't, I feel like, playing as well as I'm playing today".
The pair traded breaks at the start of the second, with Bautista Agut responding with a break to love courtesy of a rasping backhand return victor after a demoralising opening game of the set.
However, as he did against Daniil Medvedev in round two, he stopped his opponent in his tracks at the death to advance to the final eight.
The two then went back and forth in the deciding set, both missing guilt-edge opportunities to break serve, until Federer found a breakthrough in the ninth game before serving for the match.
The Japanese eighth seed came through a tight match against American Sam Querrey to prevail 7-6 (9-7), 6-4.
The Argentine world number four, who had already been suffering with a virus, lost his footing at 5-5 in the first set against Croatia's Borna Coric. Del Potro had the knee wrapped but called it quits after losing the first set 7-5.
Kristina Kucova, who caused an upset Monday after she knocked out Jelena Ostapenko, glided through her match with Viktoriya Tomova 6-1, 6-0.
Thiem has played in Shanghai four times and has never advanced to the third round.
A Masters event is a level below a Grand Slam, but Djokovic was rapt to crush Cecchinato.
"In the third set I really started to figure it out, as well, how aggressive or how tactical I wanted to make the match", said Federer. I did everything that I needed to win.
But the Spaniard earned a piece of personal history after that, winning the second set - the first time he had taken a set against the Swiss maestro.
A test against Chung, who defeated Djokovic at the Australian Open at the start of the year, could be up next, though, if the Korean can rediscover his own best form against Marco Cecchinato. The Serb is on a 15-match winning streak, which includes title runs at Cincinnati and the U.S. Open.
He will take on seventh-seeded Kevin Anderson of South Africa, whom he leads 6-1 on head-to-head. Djokovic defeated Anderson in straight sets in the Wimbledon final in July.
Imperious Novak Djokovic declared that he was "a completely different player" from the first half of this year after he beat France's Jeremy Chardy 6-3, 7-5 to roll into the Shanghai Masters third round on Tuesday night.