First-half goals from Nathaniel Mendez-Laing, Craig Bryson and Callum Paterson had the Bluebirds cruising to a sixth successive triumph.
But new Birmingham manager Garry Monk inspired a second-half fightback as Craig Gardner’s penalty and Maxime Colin’s late strike gave the relegation strugglers hope until the final whistle.
The win moves the Bluebirds onto 73 points with 10 games remaining, while Birmingham remain in the relegation zone, two points adrift of safety.
Neil Warnock had been named the Championship’s manager of the month for a record-equalling ninth time after guiding his side to 16 points from a possible 18 in February.
It looked like they would be adding another three to their tally of 70 after 12 minutes when Mendez-Laing scored his first goal since August.
The Bluebirds won possession back deep inside Birmingham territory and fed the powerful winger, who cut inside and sent a low shot past heavy traffic and into the bottom corner.
The expectant Cardiff fans only had to wait 10 minutes to see their side score again.
Monk’s men were found wanting at another set-piece as they failed to deal with Junior Hoilett’s corner.
Left-back Joe Bennett pounced on a lacklustre clearance to drive the ball back into the box and into the path of Bryson, who steered it past Blues goalkeeper David Stockdale.
There was still time for a third goal in first-half stoppage time thanks to Paterson’s second goal in as many games.
The Scotland international burst into the box and managed to make contact with Bennett’s dangerous cross to put his side 3-0 up on the stroke of half-time.
But Birmingham were given a ray of hope by referee Peter Bankes shortly after the restart. The Merseyside official blew his whistle at a corner to award a penalty for a pull on the shirt of Marc Roberts, who did not appeal for a spot kick.
Gardner forced the penalty past Neil Etheridge to make it 3-1 after 54 minutes, before they had another opportunity to cut the gap.
Jota’s corner evaded the Cardiff defence and fell into the path of Blues captain Michael Morrison, but Etheridge made a reaction save to deny him from three yards out.
There was still time for Colin to cut-in and fire a deflected shot past Etheridge to make it 3-2 in stoppage time.
Pivotal game in Group E almost a pick ‘em with the bookies