Blues got back to winning ways in West London thanks to goals from Michael Morrison and Clayton Donaldson.
Morrison powered in a David Cotterill corner with 19 minutes to play before Donaldson made sure of the points with virtually the last kick of the game.
The opening 45 minutes saw both sides enjoy spells of dominance, with Blues making the brighter start. Donaldson, Demarai Gray and Cotterill were all busy in the early exchanges with the latter firing a left-footed effort wide from the edge of the area.
Brentford responded to that and began to move the ball around with purpose, making life difficult for Blues. The Bees' best chances all fell to striker Marco Djuricin who dragged two shots wide before forcing Tomasz Kuszczak into a low save before the half-hour mark.
The hosts had David Button to thank for keeping the score level at the break when Cotterill met an excellent cross from Stephen Gleeson at the far post. The Brentford 'keeper did well to palm the Welshman's header away at close range.
After the interval it was Kuszczak's turn to come to his side's rescue. Bees' striker Lasse Vibe raced away down the Blues left, skipped past Michael Morrison and drove into the box but Kuszczak stood tall to beat the ball away.
After that Blues seized control and carved out a number of chances the best of which fell to Gray. Michael Kieftenbeld threaded through a lovely ball to find Paul Caddis, he picked out Gray with a low cross but the winger miscued his finish.
But the pressure eventually told after 71 minutes when captain Morrison rose to power home a Cotterill corner in front of the travelling supporters.
Blues had opportunities to extend their lead but had to endure a heart-stopping moment when Alan Judge rattled the crossbar.
The visitors always looked in control though and Donaldson made sure that the points would be heading back to Birmingham in the final seconds of additional time. Gleeson played a ball between the two centre-halves and the former Bees striker kept his cool to finish and ensure Blues' climb to joint third in the table.