Birmingham took the lead on 25 minutes when David Murphy sent in a shot that was parried to Sebastian Larsson and he slammed the ball home.
But six minutes later and Blues were pegged back when Matty Fryatt equalised for the Foxes.
In the second half Kevin Phillips got on the end of a Larsson corner to make it 2-1 with twelve minutes to go.
And with just two minutes remaining Levi Porter looked like he had earned a draw for Leicester when he fired home to make it 2-2.
And so it was left to Phillips who grabbed a dramatic winner just before the final whistle.
Blues: Doyle, Parnaby, Martin Taylor (Jaidi 46), Ridgewell, Murphy, Larsson, Nafti, Carsley (Mutch 86), McSheffrey (Jerome 67), Bent (Phillips 67), McFadden (O’Connor 67).