Neal Maupay sent the Bees ahead in the 11th minute, but West Ham turned the match around to lead 2-1 in the 26th minute, with Mohammed Kudus and Jarrod Bowen on the scoresheet.
Thomas Frank's side made it 2-2 in the 55th minute courtesy of an own goal from Konstantinos Mavropanos, though, before Collins won it for the hosts 15 minutes later.
The result has moved Brentford, who have now won their last three Premier League matches, into ninth position in the table, while West Ham have dropped to 11th.
A slip from Mark Flekken almost allowed Michail Antonio to send West Ham ahead inside the first minute of the match, but the Brentford goalkeeper just managed to clear at the vital moment.
The home side managed to make the breakthrough in the 11th minute of the contest through Maupay, who headed into the back of the net from close range after Frank Onyeka had kept the danger alive with West Ham failing to clear their lines despite having a number of opportunities.
The response from the Hammers was strong, though, and they levelled in the 19th minute, with Kudus finding the back of the net with an acrobatic finish after meeting a cross from Antonio.
David Moyes's side then took the lead in the 26th minute of the match through Bowen, who converted from close range after Kudus had directed a cross from Said Benrahma against the post.
There was a VAR check for a possible handball, but the goal was awarded, with West Ham managing to turn the game around in the space of 15 minutes.
Mathias Jensen struck into the side-netting in the period that followed, before Christian Norgaard headed wide of the post from a corner, with Brentford passing up two good chances to level.
Benhrama and Antonio then got in each other's way down the other end, with neither able to turn a low cross into the back of the net from close range when it looked like a third for West Ham.
Brentford continued to cause problems down the other end, with Bryan Mbeumo just missing the post with a free kick, before he fired over the crossbar late in the first period and then sent the ball wide from close range, with the home side somehow entering the half-time break behind.
Norgaard had the first half-chance of the second period when the ball fell kindly for him in a dangerous area, but the midfielder's effort was too high.
Brentford did manage to level the scores in the 55th minute, though, with Mavropanos turning into the back of his own net from a brilliant Mbeumo delivery into the penalty box.
The Bees then took the lead in the 70th minute through Collins, who produced a towering header at the far post from a Jensen delivery with the entertaining contest swinging the way of the home side.
West Ham came close to levelling in the 80th minute following smart work from Kudus, who managed to pick out Pablo Fornals, but the midfielder fired his effort just wide of the target.
Brentford had chances to wrap up the points late on through Maupay and Mbeumo, but the Bees were not made to pay for the missed opportunities, with Collins's header proving to be the winner.
Next up for Brentford is a trip to Liverpool next Sunday, while West Ham will be bidding to return to winning ways when they host Olympiacos in the Europa Conference League on Thursday.