Jay McEveley's long-range strike gave Derby a 55th minute lead, but Scott Dann headed the Premier League side level before super-sub Kevin Phillips set up a late winner for Liam Ridgewell.
After an opening half hour that did not contain a moment of note, the tie came to life when Cameron Jerome got in on the right and his low shot was pushed behind by Stephen Bywater.
Derby responded through Stephen Pearson, who was put in by Michael Tonge on the left and his shot was parried at his near post by Joe Hart.
That sparked the home side into life and in the 39th minute, Kris Commons whipped in a low cross that Rob Hulse just failed to connect with.
There was another narrow escape for Birmingham a minute later when a free-kick glanced off Stephen Carr but Shaun Barker could only prod the ball goalwards and Hart saved.
But the keeper was at fault 10 minutes into the second half when McEveley shot from 25 yards and the ball dipped before bouncing over Hart and inside his left post.
Robbie Savage was booked against his former club as Derby fought to preserve their lead, but the visitors were level in the 73rd minute.
James McFadden swung in a corner from the left and Dann's downward header went in off a Derby player on the line.
It was another set-piece that took Birmingham through when Craig Gardner's 25-yard shot went through the wall and after Phillips struck a post, Ridgewell followed in to bundle the ball over the line.
Savage almost forced a replay with a 25-yard shot in the third minute of stoppage time which Hart turned over, but Birmingham then ran down the clock to book a place in the quarter finals.