Jon Stead's late goal saw off Leicester City and earned Bristol City a first win in eight games.
Lloyd Dyer fired the Foxes into the lead but Kalifa Cisse levelled on the stroke of half-time with a neat finish.
The Robins went ahead when Brett Pitman stroked home Stephen Pearson's pass, only for Neil Danns to scramble home an equaliser Tom Kennedy's cross.
Minutes later, Stead reacted quickest after Pitman hit the post to give the home side three points.
Victory lifted Derek McInnes's side five points clear of the Championship relegation zone.
Dyer opened the scoring four minutes before half-time, lashing into the top corner after the Bristol City defenders failed to clear their lines.
Bristol City responded through Cisse, who coolly slotted beneath goalkeeper Kasper Schmeichel, before Pitman struck nine minutes into the second half.
They were pegged back when goalkeeper David James was unable to cut out Kennedy's cross and Danns was on hand from close range.
But there was one more twist in the tale when striker Pitman, finding space in the penalty area, struck the woodwork and Stead pounced to bag his second goal of the season.
Bristol City manager Derek McInnes:
"I don't think anybody gave us a chance apart from the boys in our dressing room. We believed we would win the game.
"I felt we kept them at arm's length, that's why I was so disappointed to the lose the first goal.
"Thankfully there was enough spirit and energy amongst them to get back into the game.
"To do it the way we did it, against a team who don't concede many goals, and score three goals, was testament to the players."
Leicester City manager Nigel Pearson:
"We conceded some very poor goals and subsequently put the game at risk.
"Two goals away from home should be enough to win a game but the manner in which we conceded goals tonight is not pleasing.
"We've made mistakes at the back but we've not defended well enough as a team.
"It is frustrating because we've worked exceptionally hard in the last few weeks to try and get in contact with the places above us and you have a night like tonight, where all that hard work is almost undone because of the manner of the defeat.
"If you lose a tight game where a bit of brilliance wins it you've got no complaints but I'm disappointed tonight with the manner of our defeat."