The game exploded into life in five pulsating minutes when the Bees took the lead thanks to a goalkeeping blunder by Scott Flinders.
Niall McGinn’s speculative lob slipped through his hands to gift the home side a lead that they held for just three minutes.
Brentford’s jittery defence failed to clear a free-kick and Sam Collins’ defected effort found the bottom corner.
But Uwe Rosler’s side sneaked into the play-off places after Toumani Diagouraga was brought down in the area and Gary Alexander fired home the spot-kick at the second attempt.
Alexander came closest to breaking the deadlock in the first half but his header from point-blank range was straight at Flinders.