Argentine Juan Martin del Potro overcame a slow start to outlast France's Richard Gasquet 7-5 7-6 (7).
It soon went from bad to worse for the top seed as Bautista Agut struck a clean forehand up the line to break again as he reeled off four games in a row to lead 4-1.
Federer, the defending champion, beat Daniil Medvedev 6-4, 4-6, 6-4 in the second round despite being broken late in the second set.
Curiously, Bautista Agut - who is better known for his durability and baseline rallies - served more aces than Federer and he had the better of proceedings in the second and third sets. "Since Hamburg I got a lot of confidence and that helped me in Beijing".
Bautista Agut, a finalist here in 2016, finally offered Federer an opening to take control by surrendering his serve in the ninth game of the third set.More news: Florida takes stock of devastation from Hurricane Michael
The Spaniard folded at the end of a 27-shot rally to surrender the first break of the match to the world No. 2, who soon wrapped up the first set.
World number seven Dominic Thiem's bid to qualify for the next month's ATP World Tour Finals suffered a blow as he was edged out 6-4 6-7 (8) 7-6 (4) by Australian Matthew Ebden.
Djokovic enjoyed a measure of revenge as he booked his spot in the Shanghai Masters quarter-finals with a comfortable 6-4 6-0 victory against Marco Cecchinato.
"It wasn't easy to play for me today, " said del Potro, who reached the China Open final last week.
Fresh off the biggest title of his career in Tokyo, Medvedev saved a break point early in the second set and that gave him momentum to grab a break of his own to force a decider.More news: Rishabh Pant breaks into Indian ODI team after runs in Tests
Since Djokovic lost that French Open match to Cecchinato, he's won 28 of his 30 matches.
But he exploded back to life mid-season, winning Wimbledon, the Cincinnati Masters and US Open.
Anderson ousted 10th-seeded Stefanos Tsitsipas of Greece 6-4, 7-6 (1).
Fifth-seeded Marin Cilic became the highest seed toppled in Shanghai when 48th-ranked Nicolas Jarry of Chile rebounded for a 2-6, 7-6 (6), 7-5 second-round win.More news: Pentagon Grounds Troubled F-35 Fighters After First Crash
- Hurricane Michael rips through Florida's Panhandle
- #HimToo poster boy flips the narrative after mom's viral tweet
- Sarah Silverman Rips 'Too Far Gone' White Women Who Voted for Trump
- Bronson Burgoon has 1st-round lead at CIMB Classic
- Crew Rescued After Russian ISS Launch Fails
- Roberts asks federal judges in Colorado, other states to handle Kavanaugh complaints
- Don’t be too hard on him, Vladimir Putin tells Khabib’s father
- Google Plus shutting down as social network bug exposes private data
- ISS crew in 'good condition' after failed space launch
- Borderlands 2 VR announced for PlayStation VR