Brentford rekindled their play-off bid as Bournemouth missed the chance to return to the top of the Championship.
The Bees went ahead through Jonathan Douglas, who rifled home after Yann Kermorgant was caught in possession.
But then a Brentford mistake let in Marc Pugh, who hit the post but buried the rebound to level the scores.
Alex Pritchard fired in a 35-yard free kick before half time and Pritchard crossed for Chris Long to add a third late in the game.
Half-time substitute Ryan Fraser had revitalised Bournemouth after an off-key first period, but was denied by the foot of the post and then by onrushing keeper David Button.
As the visitors poured forward, Brentford’s Jota also hit the frame of the goal and was denied twice by keeper Artur Boruc in the dying minutes, but substitute Long’s first goal for Brentford finally settled an enthralling end-to-end match between two of the Championship’s unlikeliest promotion contenders.
The Bees, who announced this week that boss Mark Warburton would leave at the end of the season, struck first when Kermorgant’s hesitation was punished as the lively Pritchard crossed and Douglas made no mistake with a measured left-foot finish.
Chants of “Warburton, Warburton” could immediately be heard around Griffin Park as the home fans made their support clear.
But Bournemouth levelled when Toumani Diagouraga inadvertently deflected a through ball into the path of Pugh, who rounded Button and though his first effort hit the post, he volleyed in the rebound.
Boruc was rescued by Steve Cook’s goal-line clearance from an Andre Gray effort, but the Pole was found wanting as Pritchard’s curling free-kick flew to the goalkeeper’s left and an attempted punch left both ball and keeper nestling in the net.
Warburton is leaving as he disagrees with owner Matthew Benham’s desire for a more statistics-based approach to recruitment.
But a wholehearted display from his players, who had to defend for their lives after the break, ensured Brentford prevailed by three to one in the day’s most important statistic.