Substitute Scott Hogan was the penalty hero as his late spot-kick gave Birmingham a much-needed 1-0 win against promotion-chasing Swansea after team-mate Lukas Jutkiewicz had missed one.
Hogan blasted his penalty past goalkeeper Freddie Woodman in the first minute of added time after Ivan Sunjic had been bundled over by substitute Yan Dhanda.
The result – Blues' second home win in a row under new head coach Lee Bowyer – moved them up to 20th and six points above the relegation zone, but third-bottom Rotherham have four games in hand on them.
Third-placed Swansea suffered their third straight loss and appear to have almost blown their chances of automatic promotion as they are now nine points off second place.
Swansea created the first chance. A free-kick on the right from Connor Roberts found Jamal Lowe, whose well-struck shot on the turn from a tight angle was tipped over the bar by home goalkeeper Neil Etheridge.
Birmingham responded with a stooping header from Jutkiewicz at the far post which flew wide from Alen Halilovic's corner.
Bowyer's side had the next chance when Halilovic cut inside from the right and let fly, only for his shot to be headed away by Ryan Bennett then hit Jonathan Leko for a goal kick.
Blues were presented with the perfect chance to take the lead in the 32nd minute.
They were awarded a penalty after Roberts took Leko's legs from under him as he shaped to shoot.
Jutkiewicz drove the spot-kick hard and low but it was far too close to Woodman, who comfortably blocked with his right knee, sending the ball high into the air then to safety.
It was Jutkiewicz's fifth miss in 13 penalty attempts in his career and Woodman's fifth penalty save in eight since joining Swansea on loan from Newcastle, initially in August 2019.
Blues had enjoyed much of the play and looked the most threatening team in the first period but had nothing to show for it.
Swansea carried the greater threat the longer the game wore on.
Dhanda's 25-yard free-kick was tipped behind by Etheridge and Lowe's rising drive from a similar distance was deflected over.
Then came the decisive moment. Defending a ball at the far post, Dhanda caught Sunjic to send the midfielder sprawling and referee Tony Harrington awarded Blues their second penalty of the game.
This time, they made no mistake as Hogan blasted the ball high to Woodman's right, giving the goalkeeper no chance, for his seventh goal of the season.