Andre Gray put the Londoners in front just before the interval after being set up by Alan Judge, and the game was made safe in the final seconds when substitute Nick Proschwitz scored from close range.
Brentford had the first effort on goal when a ricochet from midfield put Gray clear, hoping to capitalise on his fortune, he hit an early shot but Adam Collin gathered.
Rotherham responded quickly by striking the crossbar for the first time. Kari Arnason launched a trademark long throw into the box for Kirk Broadfoot but his header had too much on it to drop in underneath the bar.
Ben Pringle almost turned in the rebound but goalkeeper David Button was alert enough to push it out for a corner.
Paul Taylor then created another good chance for the home side. After bursting down the left flank, he found fellow winger Ben Pringle at the far post. Pringle shot on his favoured left foot but it was deflected away by Harlee Dean.
Matt Derbyshire then fired just over for Rotherham from long range before Alex Pritchard at the other end headed over when found by a clever ball from Judge.
Brentford looked to have overturned Rotherham’s early dominance and Jota Peleteiro came close with a driven strike from the edge of the box.
Rotherham then hit the crossbar again with dangerman Taylor finding space on the edge of the box and curling an effort that beat Button but not the woodwork.
They were to be hit with a sucker-punch two minutes into added time with Gray being slid in nonchalantly by Judge.
Gray fired powerfully into Collin’s top corner after being allowed too much time and space by the Rotherham back line.
After a quiet start to the second half, Derbyshire should really have equalised for Rotherham on the hour after he capitalised on loose defending from James Tarkowski.
Derbyshire lost his man and was in on goal but he tamely struck it towards Button who saved with his legs.
To add to the home fans’ frustrations Button was out quickly enough to deny substitute Jordan Bowery an effort on goal after he was put in by fellow sub Febian Brandy.
Taylor was then denied by Button after meeting a deflected cross on the volley from the edge of the penalty area.
Brentford substitute Scott Hogan had to be carried off with what looked like a nasty injury that added a substantial amount of time onto the end of the game.
Rotherham attempted to make the best use of the time left. Richie Smallwood had a shot from distance and Richard Wood headed wide from a corner.
Brentford sealed the game off with seven minutes gone into the eight that was added. Proschwitz had been sent on to hold the ball up but he was on hand to tap in from Jon Toral’s cross to seal the points.