Birmingham crashed out of the FA Cup in the third round as Chris Brandon struck a late winner for League One side Huddersfield at the Galpharm Stadium.
Brandon's volley stunned the visitors
Luke Beckett scored from close range after four minutes for Huddersfield but Garry O'Connor struck after Matt Glennon parried Fabrice Muamba's shot.
Brandon was denied by Maik Taylor and the woodwork from a header.
But Beckett crossed for the impressive Brandon who volleyed home to seal Huddersfield's place in the next round.
The hosts were ahead after just four minutes when Danny Schofield took possession from deep but was not tackled as he strode into Birmingham territory.
He made light work of Radhi Jaidi's attempted block and after a quick give-and-go in the penalty area, he unleashed a shot at Taylor, who spilled the scuffed effort.
Beckett was first to the loose ball and he stabbed into an empty net.
A quick break following a corner drew the visitors level in the 20th minute.
Taylor set Daniel de Ridder free down the left and he played in Muamba, who shrugged off Robbie Williams' attentions to make room for a shot.
Glennon got a firm hand to it but when the ball broke it found O'Connor, who slotted home with ease.
The equaliser steadied Birmingham and only a linesman's flag stopped them taking the lead after 24 minutes.
De Ridder was again the architect, breaking at pace and curling a cross high into the Huddersfield penalty box.
The ball took a deflection on its way to O'Connor who poked his shot past Glennon on the volley before seeing his celebrations cut short by an offside verdict.
Brandon climbed highest from a free-kick and was unfortunate to be denied by a combination of Taylor and the woodwork.
Birmingham then took the initiative, with Gary McSheffrey and O'Connor both having passable shots, but McSheffrey failed to impress on Birmingham's left despite plenty of possession.
And it was the home side who seized the initiative with Beckett, clearly tiring but charging manfully down the wing, heaving a cross deep into the danger area.
As Liam Ridgewell and Jaidi were pulled to the near post, Brandon was given space at the opposite upright to drill home his volley.
Huddersfield: Glennon, Sinclair, Mirfin, Berrett, Williams (Skarz 46), Kamara (Jevons 79), Holdsworth, Collins, Brandon, Beckett, Schofield.
Subs Not Used: Smithies, Young, Killock.
Booked: Brandon, Skarz, Berrett.
Goals: Beckett 4, Brandon 81.
Birmingham: Maik Taylor, Kelly, Queudrue, Ridgewell, Jaidi, McSheffrey, Muamba (Doyle 66), De Ridder, Larsson, O'Connor, Forssell (Jerome 62).
Subs Not Used: Sadler, Parnaby, Mutch.
Booked: Queudrue, Ridgewell, Jaidi.
Goals: O'Connor 19.
Ref: Steve Tanner (Somerset).
BBC Sport Player Rater man of the match: Huddersfield's Luke Beckett 8.33 (on 90 minutes).
Please note that you can still give the players marks out of 10 on BBC Sport's Player Rater after the match has finished.