Mikael Forssell came off the bench to score Birmingham's winner four minutes from time as they beat Blackburn and climbed out of the relegation zone.
Birmingham striker Mikael Forssell celebrates his crucial winner
Forssell controlled a cross from the excellent Julian Gray and slammed a fine left-foot shot into the corner.
Birmingham had gone ahead just after the hour mark when Gray crossed from the left and Nicky Butt converted.
Ex-Blues midfielder Robbie Savage levelled with a low shot past Maik Taylor before Forssell's late strike.
The tension-wracked finale leaves the Blues ahead of Portsmouth in the Premiership on goal difference, with only three games each left to play.
This was Birmingham's game in hand, and in the teeming rain they knew they had to win to keep their survival hopes alive.
In a largely dominant display it was the hosts who had the first chance, Jermaine Pennant crossing from the right and Gray seeing a sweet volley brilliantly tipped over by Brad Friedel.
They created another one soon after, but not for the first time this season Emile Heskey wasted it, heading Damien Johnson's cross woefully over.
Birmingham suffered a hammer blow before the break, as the influential Pennant had to be withdrawn with a groin injury, replaced by Mario Melchiot.
But twice they could have gone in front as the clock ticked down towards the interval.
First Chris Sutton hopelessly mis-kicked when presented with a six-yard sitter by Gray, before Gray lashed in a 20-yard left-footer that flew inches wide of Friedel's goal.
Blackburn - still chasing a European place - looked laboured, and were only on level terms due to Birmingham's profligacy.
Martin Taylor was next to fluff his lines, sneaking in at the back post to meet a Gray free-kick, only to glance his header wide from close-range.
They were nearly made to pay, too. Zurab Khizanishvili met an inswinging corner ahead of the Blues defence but saw his downward header cannon back off the post.
Minutes later, Birmingham were ahead. Heskey summed up his evening by mis-kicking, but the ball fell to Gray and his accurate centre was gleefully converted by Butt.
Just as it looked like Birmingham were in the driving seat, their nightmare season took another devastating twist.
Maik Taylor saved sensationally from Rovers substitute Sergio Peter, but the ball fell invitingly for Savage to clip the ball home - his first ever goal for the club.
Thankfully for the St Andrews faithful, there was another sting in the tail.
Once again Gray sent over a fabulous cross and Forssell took a touch before hammering past Friedel to send the crowd and Steve Bruce into raptures.
Birmingham manager Steve Bruce:
"Mikael has come off the bench and scored what could end up being the biggest goal for us for some time.
"We've kept it alive. A week ago I maybe thought we were dead and buried, but we've managed to dig out results.
"The players have been terrific and we've given ourselves an outstanding chance of staying up."
Blackburn boss Mark Hughes:
"I'm very disappointed from our point of view. We had high hopes and wanted to win the game but it was a poor match from both sides.
"There wasn't a lot of quality on show and we didn't show enough cutting edge.
"At 1-1 we were in the ascendancy but then we switched off and didn't defend balls into the box. We're disappointed but we're still in the European mix."
Birmingham: Maik Taylor, Tebily, Cunningham, Martin Taylor, Sadler, Pennant (Melchiot 37), Johnson, Butt, Gray, Sutton, Heskey (Forssell 67).
Subs Not Used: Vaesen, Kilkenny, Bruce.
Booked: Cunningham, Tebily, Johnson, Gray, Sutton.
Goals: Butt 62, Forssell 87.
Blackburn: Friedel, Neill, Todd (Mokoena 74), Nelsen, Khizanishvili, Emerton (Kuqi 71), Reid, Savage, Pedersen (Peter 45), Bentley, Bellamy.
Subs Not Used: Enckelman, Dickov.
Goals: Savage 78.
Ref: U Rennie (S Yorkshire).