It was a thrilling game at the Gtech Community Stadium as the Hammers led at half-time after initially going behind, only to see the Bees retake the lead and record their fifth win from five Premier League games in this fixture.
Brentford's Neal Maupay ended a 14-month goal drought when he opened the scoring in the 11th minute but the lead lasted just eight minutes before West Ham's Mohammed Kudus scored a stunning volley with his back to goal.
Kudus saw another shot come off the post with Jarrod Bowen cleaning up to make it 2-1 following a long VAR check for handball but Brentford equalised in the second half when Konstantinos Mavropanos headed a cross into his own net.
The hosts were much the better team in the second half and took the lead for a second time when club record signing Nathan Collins scored with a towering header to clinch the points as Thomas Frank's side moved up to ninth. West Ham are 11th.