Sergi Canos' hat trick was enough to see off a gritty Cardiff side that was kept in contention by a brace from Will Vaulks. The Bees, unbeaten in 15 matches in all competitions, remain fourth in the table.
Story of the match
Canos first had involvement in the fifth minute as he played in Ivan Toney, who was rested in the midweek EFL Cup victory over Newcastle United, but Joe Ralls intervened before the striker could get in a shot.
Alex Smithies was then called upon to collect Canos' first effort on target four minutes later after Henrik Dalsgaard had played him in with a lovely diagonal ball.
After Brentford goalkeeper had seen off some danger, Cardiff again were on the attack in the 18th minute as Will Vaulks sent a ball in for Sheyi Ojo on the edge of the box that was intercepted.
Canos had a couple of more chances, slicing his volley wide then having a shot blocked. Ethan Pinnock then appeared to get away with a trip on Harry Wilson on the half-hour mark.
Dalsgaard then whipped in a cross that was cleared by a combination of Vaulks and Sean Morrison before Cardiff struck in the dying moments of the first half.
Playing a neat one-two with Robert Glatzel, the Welshman beat Raya with a stunner from 60 yards on the halfway line to send the Bluebirds into the dressing room with a 1-0 lead.
Five minutes into the second half, Brentford won a corner that Toney created when his shot from Canos' corner was headed out by Curtis Nelson. The Spaniard's 20-yard volley was then looped over Smithies to draw the Bees level.
Smithies then tipped over Toney's mishit volley and four minutes later, Canos set up Emiliano Marcondes, but he fluffed his chance and dribbled harmlessly wide.
After Raya had collected from a Glatzel chance, Canos doubled the visitors' lead at the other end as he beat Leonardo Bacuna, faked a shot then drilled one low past Smithies to make it 2-1 Brentford.
Another chance by the electric midfielder was just wide, but he completed his hat-trick on 73 minutes after dinking Smithies at the far post and seemingly put the game out of reach.
Three minutes later, Morrison wins a knockdown from a corner, gets it to Vaulks, who sees his effort deflect off of Toney and past Raya to cut the lead in half.
Both teams were lucky to have avoided conceding a penalty towards the end of the match, Dalsagaard barging Glatzel out of the way and a minute later, Morrison tripped Toney in the box.
That was the last action of this five-goal thriller that sees Brentford look for all the world like a team that will playing in England's highest division next season.
Man of the match: Sergi Canos
It can't be anyone else. His hat-trick was scored in a variety of ways and he also was instrumental in both having more chances than the ones he converted while setting up teammates in what was one of the best individual performances of the season.
Brentford without much involvement from Ivan Toney
By the lofty standards he's set for himself since his move from Peterborough United, this was a poor game from the 15-goal man. He didn't really have a notable chance in the match and saw Vaulks' second go off of his body. In some sense, this opened the door for Canos to show the Bees aren't a one-man team in attack.
Cardiff didn't address the problem down the left-hand side
Bacuna was exposed time and again by Canos and the Bluebirds did nothing to correct the problem. Despite Vaulks' best efforts, this issue, which Brentford took advantage of almost every time it arose, cost Cardiff the game.