Trailing Shandong Luneng and Liaoning by three points at the start of play, but holding a superior goal difference, Shanxi knew a win would keep them up.
They were left shattered though by a late winner from Zhao Junzhe, who claimed the decisive goal in the 87th minute.
Liaoning led from the 23rd minute when Vlatko Grozdanoski netted, but a penalty equaliser from Anselmo in the first minute of the second half brought the teams level.
And although Yu Hanchao struck from the spot for Liaoning in the 51st minute, Anselmo scored again four minutes later.
There was all to play for, but as Shanxi pursued a winner they were floored by Zhao's late goal.
Shandong made sure of their safety with a solid 2-0 home win over bottom side Henan Jianye, thanks to Gilberto's goal in the 37th minute and a security effort from Han Peng six minutes from time.
Dalian Shide finished third bottom of the table after a 3-0 home loss to Guizhou Renhe, whose goals all came in the final half-hour from Chen Jie, Hai Yu and Rafa Jorda.
Champions Guangzhou Evergrande slipped to a 1-0 defeat away to third-placed finishers Beijing Guoan, Xizhe Zhang with the last-minute winner.
Second-placed Jiangsu Shuntian, their title hopes extinguished last week, were held 1-1 by Guangzhou, taking a 31st-minute lead through Ke Sun but being pegged back in the 90th minute by Lu Lin.
Didier Drogba set Shanghai Shenhua on their way to a 3-0 home success over Qingdao Zhongneng, opening the scoring after 74 minutes. Song Boxuan and Joel Griffiths scored in the last 10 minutes.
Dalian Aerbin finished their campaign with a 2-1 win at Hangzhou Greentown, goals from Yu Dabao and Peter Utaka countering a reply from the penalty spot by Song Wang.
Changchun signed off with a 1-0 win away to Tianjin Taida, earned by a seventh-minute goal from Marquinhos.