As they stood, China were set to miss out on a berth as the best third-placed team in all the groups, despite starting the evening three points ahead of Lebanon and with a superior goal difference.
But deep into the second half, Thailand's Adisak Kraisorn scored in Bangkok to make it 5-2, before Zhang Xizhe slotted the crucial penalty that took China to the 2015 tournament in Australia.
The dramatic turn of events, played out within minutes of each other but thousands of kilometres apart, will have left China's new coach Alain Perrin in no doubt about the size of his task.
While China heaved a sigh of relief, former champions Iraq were left to celebrate leap-frogging the visitors into Group C's second automatic qualifying spot thanks to two goals from 2007 hero Younis Mahmoud.
Mahmoud, who scored the winner in Iraq's 1-0 Asian Cup final win against Saudi Arabia seven years ago, struck twice in the first half before Ali Adnan netted their third after the break.
The second automatic berth in Group C and the spot for the best third-placed team were the only ones up for grabs as qualifying wrapped up on Wednesday, with 13 teams already locked in.
Hong Kong and Syria also had their flickering ambitions extinguished when they lost 3-1 to Vietnam and 2-1 to Jordan respectively.