The 2023 winners had been in danger of missing out on the knockout stages for the first time since 2012-13 after falling behind to a Raphael Onyedika strike in their must-win clash at the Etihad Stadium on Wednesday.
They hit back after the break through Mateo Kovavic before an own goal from Joel Ordonez and further strike from impressive substitute Savinho carried them to a 3-1 win.
That prompted sighs of relief from all round the ground as City lifted themselves to 22nd position in the league phase.
City's night had started badly when a merchandise kiosk outside the stadium caught fire and it took a stirring second-half revival to ensure their European hopes also did not go up in smoke.
A dismal 4-1 defeat at Sporting Lisbon followed by a calamitous 3-3 draw with Feyenoord and further losses to Juventus and Paris Saint Germain had left City's campaign hanging by a thread.
PSG's Ousmane Dembele scored a hat-trick in his side's 4-1 Champions League win. (AP PHOTO)
PSG also faced a shock early exit, but a hat-trick from Ousmane Dembele helped them win 4-1 at VfB Stuttgart, which eliminated the Germans.
Liverpool finished top despite dropping their first points in a 3-2 defeat at PSV Eindhoven with an understrength team, ahead of Barcelona who were held 2-2 by Atalanta who with the draw lost their top eight place for direct entry into the last 16.
The others directly through are Arsenal, Inter Milan, whose Lautaro Martinez scored a hat-trick in a 3-0 over Monaco, Atletico Madrid, Bayer Leverkusen, Lille, who thrashed Feyenoord 6-1 to rise from 12th to seventh, and Aston Villa.
Seven-time champions AC Milan dropped out of the top eight with a 2-1 defeat at eliminated Dinamo Zagreb, and along with Atalanta, Borussia Dortmund, Bayern, Real, PSG, PSV and Benfica are the seeded teams for the play-off draw, finishing ninth to 16th.
They face the teams ranked 17th to 24th: Monaco, Brest, Feyenoord, Juventus, Celtic, City, Sporting and Brugge in a draw partly pre-determined by a bracket system.
with DPA