Dele Adebola was Bristol City's hero with a second-half double after Charlton Athletic had earlier looked the more likely winners.
The big striker turned the game with a 49th-minute equaliser, heading home Liam Fontaine's left-wing cross at the far post.
And four minutes later Adebola found room in the box to control Bradley Orr's right-wing centre with his head before stretching to volley past Rob Elliot.
It was a dramatic turnaround after Charlton had dominated the first half and deservedly taken a 29th-minute lead.
Tom Soares netted the first goal of his loan spell from Stoke City when he headed in Nicky Bailey's cross from the left.
City only found their game after Adebola's goal, but could have added to them in the closing stages.
Elliot had to make a flying save from his own team-mate when Matthew Spring lunged in to intercept a Michael McIndoe cross.
Then, with time running out and Charlton committing more men forward, Gavin Williams broke forward for City only to be denied by another good Elliot stop.
The first half had seen Charlton create all the openings and Adriano Basso had to make a brilliant 25th-minute save to keep out a low drive from Therry Racon.
Just after Soares' goal the lively Chris Dickson shot narrowly wide and Charlton couldn't get the second goal to make their position secure.
City no doubt had a half-time rocket from manager Gary Johnson and responded with a much-improved second-half display.
But they were still hanging on during five minutes of stoppage time when even goalkeeper Elliot went forward for a late Charlton corner.
The visitors already look doomed to relegation, but showed enough spirit to suggest they won't go down without a fight.