Town made it four wins in five games thanks to Josh Carson's third goal in a week as Blues mount a late, late unlikely bid for the Play-Off places.
The victory was marred by a red card to Lee Martin on the half hour and a very worrying head injury to Grant Leadbitter who was stretchered off after receiving lengthy treatment.
The winner came early in the second-half when Carson picked the ball up 30 yards out and buried a low drive past David James into the bottom corner.
Town made two changes to the side that drew against Middlesbrough in midweek, Martin and Darren O'Dea coming in for Jason Scotland and the injured Mark Kennedy. Josh Whight included in the 18 for the first time.
Former Blue Jon Stead started for the home side and threatened inside the first five minutes but the covering Carlos Edwards prevented any scare for Town.
Nicky Maynard had a shot blocked after an impressive run from Albert Adomah, the wideman then carving out another opportunity for Jamal Campbell-Ryce whose shot was beaten out by Arran Lee-Barrett.
David James held firm from crosses from Carson and Edwards and the England international did superbly on the quarter hour to keep out Connor Wickham from point blank range, the 'keeper showing great reactions to push the ball away after the Town frontman looked certain to score from Edwards' cross.
Maynard was crowded out by Gareth McAuley and Lee-Barrett after getting on the end of a long ball, Leadbitter then booked for a pull back on Albert Adomah.
McAuley prevented Maynard getting in after an exchange of passes with Stead, Marvin Elliott then sending a header over the bar.
Town were made to play over an hour with 10 men after Martin was shown a straight red card for a foul on Kalifa Cisse. Referee Booth reaching for his book a minute or so later to yellow card Stewart for a foul on Wickham.
City pegged Town back for the closing stages of the half, Jordan Spence firing over, Lee-Barrett saving well from Campbell-Ryce again, then Stead heading across goal when it looked as though he could find the net.
It was Town who got the breakthrough on 52 minutes though as Carson's fairytale continued, his left foot beating James from 30 yards after Elliott had given away possession.
Stead blasted just wide with his last touch before being replaced by Brett Pitman just before the hour as the Robins looked for an immediate response.
Town lost Leadbitter on 65 minutes after a clash of heads with Stewart, the midfielder receiving treatment from the doctor amid worrying scenes - the former Sunderland player down for seven minutes. Colin Healy his replacement.
City made second change with Cisse making way for Cole Skuse for the last 20 minutes,
Spence was booked for a foul on Carson, Damien Delaney unable to get enough on Jimmy Bullard's free-kick to put the ball back in the danger area.
City made their final change with Elliott replaced by Martyn Woolford for the final 10 minutes,
Pitman had a shot deflected wide as City searched for an equaliser, Skuse having a shot smothered by Town defending after the ball had escaped Lee-Barrett's grasp.
Wickham pulled a ball back across the box as Blues caught the Robins on the break, Lee-Barrett tipping Pitman's header over at the other end.
Bullard couldn't beat James from the edge of the box, Lee-Barrett then tipping over Pitman's chip as the game entered 11 minutes of added on time.
Pitman sent another effort just wide, Bullard in the right place to clear soon after as Blues held on for a terrific three points to set up an East Anglian derby on Thursday. Victory at Portman Road would take Town to within three points of sixth placed Leeds.
Bristol City: James, Spence, Stewart, Nyatanga, McAllister, Cisse (Skuse 72), Elliott (Woolford 80), Campbell-Ryce, Adomah, Stead (Pitman 58), Maynard. Subs not used: Gerken, Johnson, Clarkson, Edwards. Booked: Stewart, Spence.
Town: Lee-Barrett, Edwards, McAuley, Delaney, O'Dea, Carson, Leadbitter (Healy 68), Bullard, Norris, Martin, Wickham. Subs not used: Fulop, Scotland, Drury, Civelli, Whight, Peters. Sent-off: Martin. Booked: Leadbitter, Wickham.