Andy Booth came off the bench to inspire Huddersfield to victory in a heart-stopping finish.
Huddersfield were heading for defeat as the game entered five minutes of stoppage time.
The home side were 2-1 down but Booth set up an equaliser for Danny Schofield and then grabbed the winner himself in the dying seconds.
A hard, physical game saw tempers become frayed in the last 10 minutes as a player from each side was sent off.
When Town's centre-back Tom Clarke was dismissed for his second bookable offence in the 80th minute it seemed his side's chances had gone with him.
Four minutes later Brentford were reduced to 10 men when left-back Andrew Frampton saw red also for a second bookable offence.
Brentford had gone ahead in the 23rd minute with a stunning goal from Isaiah Rankin. A corner was half cleared by the Huddersfield defence and Rankin collected on the edge of the box, stepped forward and unleashed a curler into the top corner.
Huddersfield levelled 11 minutes later with top scorer Pawel Abbott's eighth goal of the season.
Abbott produced a brilliant lob from the tightest of angles which left keeper Stuart Nelson stranded.
The ball sailed over the keeper's head and went in off the underside of the bar.
Gary Taylor-Fletcher saw his shot tipped over by Nelson and then Abbott went close with a dipping effort.
Straight after the re-start Brentford caught Huddersfield cold. Within 25 seconds of the kick-off substitute DJ Campbell stunned the home crowd with his first touch.
Marcus Gayle played the ball through to Jay Tabb who squared for a simple Campbell tap-in.
Huddersfield boss Peter Jackson made a double substitution in the 65th minute when he sent on strikers Booth and Junior Mendes.
But when 17-year-old Clarke was dismissed Huddersfield looked doomed.
However, referee Eddie Ilderton allowed five minutes of stoppage time and Booth was the saviour.
In the third minute of stoppage time Danny Adams' cross was headed down by Booth for Schofield to fire home the equaliser.
Then two minutes later Nathan Clarke's long throw split the Brentford defence and Booth headed the dramatic winner.
There was controversy when Tabb was taken off with an injury just after Clarke's sending off. He was walking around the perimeter of the pitch when he was struck by a bottle top thrown from the crowd and Brentford have filed a police complaint.