Neither side was able to break the deadlock by half time, although on the quarter-hour mark David Stockdale's miscued clearance fell to Abdelhamid Sabiri, only for the ensuing effort to sail harmlessly wide.
The breakthrough came on 52 minutes for the Championship side when Lukas Jutkiewicz's headed flick-on fell to Che Adams, who had space to turn on the edge of the area before cutting a low shot beyond Jonas Lossl.
However, the Terriers equalised just after the hour through an own goal as Tom Ince rifled an effort towards Stockdale from the edge of the box, the goalkeeper making the save but then seeing the ball creep in via a Marc Roberts deflection.
Midway through the second half Jutkiewicz went down inside the box under a challenge by Matthias Jorgensen but the referee waved play on despite penalty calls from the Birmingham fans.
The game opened up in the latter stages as Stockdale pulled off a series of saves, while at the other end Adams's effort was cleared off the line by Jorgensen, but neither side could find a winner by the 90-minute mark.
The Premier League strugglers then raced further ahead with a third just three minutes later, Rajiv van La Parra slotting in a rebound after Ince's effort was kept out, before adding a fourth on 106 minutes through Ince's fierce drive into the bottom corner.
The result sees David Wagner's charges earn a fifth-round home tie against Manchester United.
BIRMINGHAM CITY (3-5-2): Stockdale; Dean, Roberts, Morrison; Jenkinson (Dacres-Cogley 71'), Lowe (Lakin 101'), Gardner, Ndoye (Jota 45'), Bramall; Jutkiewicz (Boga 86'), Adams
HUDDERSFIELD TOWN (4-4-2): Lossl; Smith (Hadergjonaj 45'), Kongolo, Jorgensen, Malone (Lowe 95'); Sabiri (Van La Parra 56'), Billing, Mooy, Ince; Quaner (Scannell 99'), Mounie