The 6ft 4ins centre back, on loan for the season from Swansea, headed in Jesse Lingard’s in-swinging corner on 65 minutes.
That made it 2-1 to the visitors and 15 minutes later he headed in Lingard’s free kick only to see red for over-celebrating.
Bartley had been booked in the first half for a foul on Danny Ward and earned a second yellow for taking his shirt off after scoring his second goal.
Victory marked Birmingham boss Lee Clark’s first win over Huddersfield since he was sacked by the club in February 2012.
The visitors took the lead early on but were pegged back when Anthony Gerrard scored on his return to the Town side after a training ground bust-up.
Gerrard, cousin of Liverpool ace Stephen, missed the previous two games following his involvement in an incident with Adam Clayton and Martin Paterson.
He made amends by flicking home a header from Adam Hammill’s free kick on 31 minutes to level the scores at 1-1.
Hammill started despite being fined and told by boss Mark Robins to “grow up” for his reaction to being substituted in last week’s defeat at Wigan.
Both teams came into this match with only two wins in their last 10 matches – with Town having lost three of their last four outings.
Birmingham made the brighter start thanks to ex-Huddersfield striker Lee Novak, who played in a wide role for the visitors.
He forced home keeper Alex Smithies into a good save early on. Lingard won a 50-50 in the centre circle and Nikola Zigic put Novak through.
Novak then helped put Birmingham in front with a shot from a tight angle on 11 minutes which Smithies did well to parry.
Serbian Zigic, who stands at 6ft 7ins, showed good athleticism to slide in at the far post and hook the rebound over the line from close range.
Novak, who joined on a free transfer in the summer, was a thorn in the side of his old club.
Smithies saved well when the Geordie fired in from 20 yards on 37 minutes and then saw a Novak header from a Mitch Hancox cross drift wide five minutes later.
The Terriers came more into it as the game went on. Sean Scannell twice went close while Ward headed over a Hammill free-kick on 23 minutes.
The sides traded blows early in the second half, with Novak again forcing Smithies to parry at one end and Hammill drilling just wide at the other.
Bartley’s purple patch and red card followed, with Brum shutting up shop after that to snuff out any threat of a Huddersfield comeback.