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: Borderlands 2 VR announced for PlayStation VR
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: Harvey Weinstein Gets One Sexual Assault Charge Dismissed
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: Bronson Burgoon has 1st-round lead at CIMB Classic
- Tyson Fury still not enrolled in WBC's Clean Boxing Program
- Pentagon Grounds Troubled F-35 Fighters After First Crash
- African Billionaire Kidnapped by Gunmen at Luxury Hotel in Tanzania
- Kanye West Goes On 10-Minute Rant During White House Visit
- US President Trump calls the US Fed 'crazy', stock declines a 'correction'
- Crew Rescued After Russian ISS Launch Fails
- Details Surface on How to Watch Apple’s Original Content
- Der Spiegel stands by Cristiano Ronaldo rape allegation reporting
- The FSF Wants Microsoft To Do More To Help Fight Software Patents
- Florida takes stock of devastation from Hurricane Michael