After a dire first half, Morten Gamst Pedersen was given a golden chance to open the scoring in the 50th minute when Nikola Zigic fouled Christopher Samba in the box - but Foster pulled off a superb save.
Four minutes later the visitors were ahead as Steven Nzonzi headed in a corner but Gardner turned the game around, converting a brilliant James McFadden pass in the 57th minute and then beating Paul Robinson from 30 yards for the winner with 19 minutes left.
Birmingham boss Alex McLeish had been disappointed with his side's display in their 2-2 draw at Sunderland last weekend and he made three changes, giving 6ft 8in striker Zigic his first start and bringing McFadden and Gardner into midfield.
Another debutant was referee Michael Oliver, who at 25 became the Premier League's youngest referee, beating the record set two years ago by Stuart Attwell.
After a reasonably bright start that saw Cameron Jerome scuff a shot at Robinson, Blues struggled to keep possession.
Blackburn played with only Nikola Kalinic up front but he was well supported by El-Hadji Diouf and Pedersen, and the latter was inches away from getting on the end of a ball from the striker as Rovers broke following a Birmingham corner.
The visitors were sending in ball after ball just under Foster's crossbar, and the England keeper did well to withstand the onslaught in a very scrappy first half.
The best chance of the opening 45 minutes came at the other end after Sebastian Larsson saw his shot deflected behind for a corner.
The Swede's wicked delivery had created both goals at Sunderland and he must have thought he had done it again when he picked out Scott Dann only six yards out but his powerful header drew a smart stop from Robinson.
It needed good defending from Michel Salgado to prevent Zigic claiming his first Birmingham goal in the opening moments of the second half after Gardner somehow dug out a cross to the back post.
Oliver had had very little to do but with 50 minutes gone he made his first big call as a Premier League referee when he spotted Zigic pulling Samba's shirt as Pedersen curled in a corner and awarded a penalty.
The Norwegian struck it well but Foster reacted superbly with a fingertip save onto the angle of post and bar.
Rovers were not to be denied, though, and five minutes later they took the lead.
Foster produced another good save to tip over Nzonzi's header from Pedersen's long throw but the barrage continued and from the corner the Frenchman found space at the near post and glanced a header into the net.
Rovers were well worth their lead, but it lasted only three minutes as the game suddenly burst into life.
A long ball from Stephen Carr found McFadden in the area and his superb volleyed pass, the first real moment of quality, left Gardner with a simple tap-in.
There were now chances coming thick and fast, although mostly at the Birmingham end, and, after Foster pulled off another good save to keep out Kalinic's low shot, Samba found himself in acres of space from Pedersen's free-kick but headed against the post.
With 24 minutes to go, McLeish gave Matt Derbyshire his first taste of life in a Birmingham shirt, the Olympiacos loanee - and former Rovers striker - replacing the disappointing Zigic.
Birmingham appeared to have weathered the Blackburn storm and in the 71st minute they took the lead out of nothing when Gardner let fly from 30 yards and found the bottom corner.
Although it was a well-struck effort that bounced in front of Robinson, the keeper would still have been disappointed to be beaten from such a long way out.
As the match went into added time, substitute Keith Fahey drew a decent save from Robinson with a sweet volley while Birmingham's only real moment of alarm came when Cameron Jerome headed just over his own bar from yet another corner.