Daryl Murphy put Blues ahead with a superb strike, his seventh goal of the campaign.
Peter Whittingham levelled the scores soon after with another sublime left footer before second-half goals from Federico Macheda and Adam Le Fondre gave Russell Slade’s side the game.
Town made two changes to the team that drew with Blackburn at the weekend, skipper Luke Chambers and leading scorer Murphy returning to the side after illness and injury, with Tommy Smith and Stephen Hunt making way.
Murphy showed attacking purpose inside the first five minutes, breaking clear but his 25 yard strike flew high and wide of the Cardiff goal.
Tyrone Mings recovered quickly to stop the danger from Craig Noone after the wideman had threatened to get in, then Dean Gerken pushed Anthony Pilkington’s curler over the bar.
David McGoldrick sent a right foot effort wide after Jonny Williams had released him, the Wales international then opening the way for Conor Sammon to strike but the Derby loanee dragged his shot past the far post.
Williams sent a low drive a yard wide, while at the other end Noone had a shot blocked by Christophe Berra in an even first 20 minutes.
Le Fondre failed to find the target from inside the Town box but on the half hour, Blues were in front, the ball breaking to Murphy at least 25 yards out and he smashed in low past David Marshall into the bottom corner.
Williams, a constant problem to the Bluebirds’ defence, won a free-kick on the edge of the box but McGoldrick couldn’t repeat his free-kick wizardry of Saturday.
Cardiff were level five minutes later though, Whittingham the equal of Murphy’s strike with a left footer into the roof of the net giving Gerken no chance.
McGoldrick’s header from Mings’ cross was hacked clear by Sean Morrison in the last meaningful action of an entertaining first-half lit up by two terrific goals.
Town got off to the worst possible start to the second-half, Macheda diverting the ball in from close range to put Cardiff ahead as the Bluebirds started brightly.
Gerken had to be alert to clear from Macheda as he threatened to get in on a back pass, then the ‘keeper sprung to his left to push Noone’s strike away from danger.
Mings picked up a yellow card that will leave him suspended for Saturday’s visit from Huddersfield, Fabio quickly followed for a foul on Williams.
Murphy was inches away from an equaliser with a header at back post after a terrific cross from Williams, with Town making a first change on 66 minutes, Balint Bajner on for Sammon.
Cardiff extended the lead soon after, Le Fondre’s shot taking a big deflection to leave Gerken going the wrong way.
Murphy almost got on the end of Berra’s flick as Town looked for a way back into the game, Town making a second change with Williams replaced by Teddy Bishop for the last 15 minutes.
Blues made a last change with Paul Anderson introduced for the final few minutes but Mick McCarthy’s side couldn’t breach the home backline as Town went down to a first ever defeat at the Cardiff City Stadium.