All the goals came from goalkeeping blunders in a game which ended with Kadeem Harris and Federico Macheda both seeing red for Cardiff.
Andre Gray gave the home side a first-half lead, but goals from Macheda and Alex Revell turned things round for Cardiff.
The Welsh club came to west London with a game plan to stifle the fluent Bees by breaking the game up at every opportunity, and Brentford at times looked rattled by their physical approach.
Yet the Bees took the lead midway through the first half after a howler by their former stopper Simon Moore, who could only parry Alex Pritchard’s dipping free-kick into the path of Gray to bundle home from close range.
The hosts should have put the game beyond doubt by the break, only an acrobatic Moore save denying Pritchard’s deflected looping shot.
Jota also caused havoc down the right flank and Gray twice went close to extending the lead before the break.
However, the Bluebirds upped the physical stakes after the interval and made Brentford pay for a lacklustre display.
Macheda drew them level on 53 minutes when Brentford goalkeeper David Button collided with his own centre-back Harlee Dean and dropped the ball into the path of the Italian, who slid home from 12 yards.
And the comeback was complete on 68 minutes when Button raced off his line to intercept a hopeful through-ball and was caught in no man’s land for Revell to chip home into the empty goal.
However, the sheen was taken off the win by two red cards for the Welshmen. Harris, on loan at Griffin Park last season, was the first to go on 78 minutes, having come on as a half-time sub, for a reckless lunge on Bees midfielder Alan Judge.
And former Manchester United striker Macheda followed him to the dressing room with minutes remaining for a second yellow card.
That sparked a frantic spell of pressure from Brentford which saw James Tarkoswski head over when well placed and Tommy Smith’s goal-bound drive blocked by a melee of City bodies as Russell Slade’s men held on.
Cardiff almost snatched a third deep into stoppage time, but Kenwyne Jones squandered a gilt-edged chance to give the scoreline a flattering feel by blazing over after racing on to a through-ball with the home defence committed.