Radhi Jaidi opened the scoring when he headed Gary McSheffrey's corner past keeper Conrad Logan from six yards.
Sebastian Larsson converted Andy Cole's cross to make it 2-0 after 19 minutes but substitute Geoff Horsfield's second-half arrival boosted the Foxes.
Striker Horsfield was fouled by Larsson and Shaun Newton scored from the resulting free-kick.
Birmingham manager Steve Bruce:
"We won, just, but we made it a bit hairy for ourselves. There's going to be tension and edginess when you're going for promotion.
"But fair play to Leicester, they made a real fight of it in the second half.
"You are supposed to enjoy moments like this, going for promotion. But I
thought Saturday's last five minutes against Southampton were bad enough, and this was just as bad."
Leicester: Logan, Stearman, Johansson, Kisnorbo, Maybury (Horsfield 75), Newton, Jarrett (Hughes 61), Wesolowski, Mattock, Hume, Fryatt (Cadamarteri 65).
Subs Not Used: Henderson, Sheehan.
Goals: Newton 82.
Birmingham: Doyle, N'Gotty, Jaidi, Martin Taylor, Kelly, Larsson (Nafti 90), Muamba, Clemence, McSheffrey, Cole (Campbell 90), Bendtner (Jerome 84).
Subs Not Used: Maik Taylor, Vine.
Booked: Larsson, Nafti.
Goals: Jaidi 16, Larsson 19.
Ref: L Probert (Gloucestershire).