Federer and Djokovic had been a combined 13-0 in Shanghai with a spot in the semifinals on the line, but both lost Friday.
Federer saved five match points in the second set and received a point penalty in the third in the 6-3, 6-7 (7), 6-3 loss to fifth-seeded Alexander Zverev. Djokovic, the defending champion, lost to sixth-seeded Stefanos Tsitsipas 3-6, 7-5, 6-3.
"He deserved the victory," Djokovic said of the 21-year-old Tsitsipas. "He was the better player in the second and third sets. I started well in the first set, but I wasn't sharp enough."
Djokovic had been 8-0 in quarterfinal matches at the Shanghai Masters, and won four titles. Federer had been 5-0.
Federer received a code violation for hitting a ball into the stands, and then received a point penalty for unsportsmanlike conduct after flicking a ball into the air when trailing 3-0 in the third set.
When asked about the point penalty after the match, Federer didn't want to go into any detail.
"So you could write on Twitter, you mean?" Federer answered. "No, it would be nice to write something nice once also about the game.
The 22-year-old Zverev now leads Federer 4-3 in career meetings.
"I mean, they're knocking on the door big time, the young guys," Federer said. "It's exciting. They're great. It's really open now, I think, for the finish of this tournament."
Until Friday's match, Djokovic had won 24 straight sets in Asia, a run that included last year's Shanghai Masters and the title in Tokyo last week.
Tsitsipas has now beaten Djokovic twice in three matches. The Greek player defeated Djokovic in their first meeting at the 2018 Toronto tournament and Djokovic won their match in Madrid this season.
"It's the best comeback that I have ever had probably," Tsitsipas said of Friday's victory.
Tsitsipas also earned a place at the year-end ATP Finals for the first time on Friday. But that was guaranteed when third-seeded Daniil Medvedev beat Fabio Fognini 6-3, 7-6 (4) in another quarterfinal match.
Medvedev, who will face Tsitsipas in Saturday's semifinals, is one match away from reaching a sixth consecutive tournament final. He reached his first Grand Slam final at the U.S. Open, and then won titles in Cincinnati and St. Petersburg.
Medvedev leads the tour with 57 match wins this season and is 40-1 on hard courts when winning the first set. The only time he lost a hard-court match after winning the first set was against Gael Monfils in Rotterdam.
Prior to Friday's match, Fognini said Medvedev was one of the most dangerous players to face.
"If some top players like Fabio can say this about me, shows that I'm on the good way, I'm playing good, and it's not easy to play against me," Medvedev said. "Surely, yeah, that's what I tried to show today on the match and it worked out."