The Bees had endured a torrid time on the road but put that right in South Yorkshire thanks to two goals from Kamohelo Mokotjo and efforts from Said Benrahma and Neal Maupay.
The Millers had twice battled back to level up, first with a ferocious effort from Jon Taylor and then an Ezri Konsa own goal, but they slipped to a third home loss of the season which keeps them firmly in relegation danger.
Brentford's win not only extends their unbeaten run to seven games but also means that their hosts are now the only team in the division not to record an away win this season.
The Bees will have sensed this was finally going to be the day they ended their away drought as they enjoyed the perfect start.
Benrahma found himself in plenty of room down the left and rolled the ball into the path of Mokotjo, who coolly slotted into the bottom corner with less than two minutes on the clock. Rotherham's response was impressive and they levelled in the 20th minute with a fine goal.
Brentford failed to clear a corner and when the ball fell to Taylor on the edge of the area, he smashed a fierce effort into the top corner with Daniel Bentley having no chance.
Taylor came close to adding a second 10 minutes before the break, but his instinctive shot from Zak Vyner's cross went just wide.
Brentford were living dangerously and somehow they stayed on level terms two minutes later, thanks to a brilliant save from Bentley and a shocking miss from Semi Ajayi.
Bentley produced a miraculous stop to keep out Clark Robertson's header from Will Vaulks' cross, but the net should still have rippled as the rebound fell to Ajayi just two yards out but the defender inexplicably skewed his shot wide.
Having survived that scare before half-time, Brentford regrouped and began the second half strongly and after Maupay had just rolled the ball wide at the far post, they regained their lead in fine style in the 53rd minute.
A five-man move saw Benrahma open up the Millers defence with a pass to Romaine Sawyers, who played it back to Benrahma to fire home into the bottom corner.
Rotherham, to their credit, again responded well and levelled in the 73rd minute after a spell of pressure when Konsa turned a cross into his own net.
Thomas Frank's men needed just two minutes to restore their lead, though, and it was another simple goal as Rico Henry's cross was steered home by Mokotjo.
After Maupay had missed two golden chances to put the game to bed, the striker finally got his 16th goal of the season when he fired home from inside the area.