An inspired display by Lewis Price almost earned Town a point with Jimmy Juan equalising five minutes from time only for Jason Koumas to grab a last gasp winner.
Town battled valiantly with 10 men after Fabian Wilnis was harshly sent-off for a foul on Cameron Jerome on 12 minutes, Cardiff awarded a penalty.
Price produced the first of a number of fine saves though, denying Michael Ricketts.
The Bluebirds striker did find the target on 29 minutes to put the home side ahead and it looked to be the only goal of the night until Juan curled a free-kick into the net.
Koumas then took centre stage, cutting inside the Town box and firing high into the corner of the net to take Cardiff into the top six.
Richard Naylor started up front alongside Nicky Forster with Wilnis partnering Jason De Vos at the back.
Town started the game brightly with Jim Magilton's free-kick causing problems for the home defence, then Forster almost getting in at the far post.
On 12 minutes, Wilnis saw red. The Dutchman was judged to have pulled back Jerome as the Cardiff striker looked to get in on goal and referee Andre Marriner showed no mercy, awarding the Bluebirds a spot-kick at the same time.
Price threw himself to his right though to make a comfortable save from Ricketts, the second penalty save of his Town career.
Jay McEveley, who was injured in the build up to the penalty, then limped off with a knee injury to be replaced by Kevin Horlock.
Ricketts fired just wide with a left foot strike then Forster was denied by Neil Alexander in the home goal.
Cardiff's opener came just before the half hour mark. Naylor, back in defence after Wilnis' dismissal, gave possession away and Ricketts found himself in space on the right to volley past Price at the near post.
The goal gave Dave Jones' side a boost and Price had to punch clear from Jerome, with Ricketts heading Rhys Weston's cross over.
Town continued to pass the ball well though and finished the half on top. Forster's shot was blocked by Neil Cox, Gavin Williams was thwartedinside the box then Sito had a right foot shot brilliantly saved low down by Alexander.
Price denied Joe Ledley with a smart save to his right but Blues could and should have been level on the stroke of half-time, Forster's volley going straight at Alexander from six yards.
Price saved brilliantly from Paul Parry on the hour mark then the Town 'keeper kept out a Jerome drive before Jeff Whitley fired over the bar from 15 yards.
Four minutes later Price produced a wonder save from Ricketts, throwing himself to his left to palm the ball over the bar from six yards.
Billy Clarke came on for his debut, replacing Magilton on 65 minutes and was immediately in the action, setting up a strike for Forster that was blocked by Cox.
Price saved again from Parry's near post header, then moved smartly off his line to pluck Koumas' cross from Ricketts' head.
Town levelled five minutes from time, Clarke's trickery won a free-kick on the edge of the box and Juan curled a beauty past Alexander.
Price saved again from Parry and it looked enough to have won Town a point until man of the match Koumas capitalised on Sito's missed header and kept his balance to fire into the top right hand corner and hand Cardiff their first win over Blues in 40 years.
Town: Price, Sito, De Vos, Wilnis, McEveley (Horlock 14), Williams, Magilton (Clarke 65,Currie 85), Juan, Richards, Forster, Naylor. Subs not used: Supple, Proudlock. Sent-off: Wilnis.



















