Magnus Ukuonghae gave the visitors the lead just after the break, rising unmarked to power home Luke Garbutt’s corner.
But the Bees hit back in the 76th minute when Marcello Trotta slotted home Clayton Donaldson’s low near-post cross.
Chelsea loanee George Saville put the home side ahead with 10 minutes remaining, firing home a curling drive from the edge of the area.
And the comeback was complete with minutes to go when on-loan Cardiff winger Kadeem Harris headed home on his league debut from Sam Saunders’ precision cross at the far post.
Brentford might have gone in ahead at the break, but Trotta fired wide from three yards when it looked easier to score.
Adam Forshaw went close for Uwe Rosler’s side, but his dipping free-kick was tipped wide by U’s goalkeeper Sam Walker.
Saville also went close with a close-range header which just cleared the crossbar.