The 26th-ranked Davidovich Fokina fought back to win 5-7, 6-4, 6-3 and will play either Daniil Medvedev or fellow Spaniard Rafael Jodar in the final on Sunday.
The 27-year-old Spaniard combined grit, lightning-fast returns and graceful drop shots to stun the German, who will end the year world number one.
"I was a little bit nervous," Davidovich Fokina said of his shaky start.
"But I keep going, I keep fighting, every ball," he said.
The Spaniard extended his winning streak in China to nine matches, after claiming an ATP 250 title in Chengdu.
Zverev, the French and US Open champion, said fatigue had caught up with him.
"I think a break is quite necessary now," the 29-year-old told reporters, saying he would monitor his fitness ahead of a tournament in Vienna that begins October 24.
"I carried a little bit of injury, I carried fatigue into the tournament, and I'm okay to lose to a player like this today," said Zverev, who had felt his ankle at times in Shanghai.
The duo fought over long rallies in the first set, earning Davidovich Fokina a high-five from the world number two after one particularly impressive lob.

Despite a series of misjudged shots Zverev managed to avoid facing any break points in the first set.
He sprinted to send a brilliant backhand down the line, converting a crucial break point to go up 6-5.
He took the first set with an ace and looked to be heading back to the final he last reached in 2019.
Trouble arrived in the second set though as Zverev looked to be moving with some difficulty.
Davidovich Fokina worked his first break point in the fourth game but Zverev held when the Spaniard returned into the net.
Davidovich Fokina's growing pressure paid off and he successfully ran for a backhand to take the match into a deciding set.
The emboldened Spaniard raced into a 3-0 lead.
The German saved two match points but the reprieve was only a brief one.
