The Bees came from behind courtesy of second-half strikes from Sam Saunders and top scorer Clayton Donaldson to clinch the points in a classic game of two halves.
The visitors looked comfortable after Simon Ferry out-muscled Harlee Dean on the edge of the box to hammer home into the bottom corner in the 32nd minute.
They might have made it 2-0 shortly afterwards when Gary Roberts got on the end of an Alan McCormack knock down to fire against the upright.
Uwe Rosler's side were second best for an hour but rallied after Donaldson was hauled down by goalkeeper Wes Foderingham, who escaped with a yellow card.
Substitute Sam Saunders fired his 72nd-minute penalty down the middle to bring the Londoners level and spark an intense finale.
Four minutes later Donaldson, who missed a gilt-edged first-half chance, was in the right place to run onto Bradley Wright-Phillips' ball forward and lash home at the near post from a tight angle.
The big striker almost returned the compliment but Wright-Phillips' goal-bound effort was somehow blocked at point-blank range by Foderingham.
Saunders curled a free-kick over the wall and against the crossbar as Brentford's tails were up, and there was still time for Donaldson to miss another clear chance to put the game beyond doubt when he fired straight at the keeper.