Charlie MacDonald hit an impressive double and Pim Balkestein was also on target before the Bees survived a late Oldham onslaught.
Pawel Abbott had fired the home side in front after 21 minutes as he turned on the edge of the box and rifled in a superb shot. But MacDonald replied with the first of his brace, a stunning 10-yard volley from Lewis Grabban’s right-wing cross.
Brentford were grateful to keeper Wojciech Szczesny, who denied Abbott and Lewis Guy, before his team went in front against the run of play.
Balkestein, on loan from Ipswich, headed in David Hunt’s free-kick after 65 minutes and it was soon 3-1 when MacDonald seized on poor defending to sprint into the box and finish in style.
Oldham staged a grandstand finish and Abbott struck again by converting the rebound after Chris Taylor hit the post. Balkestein cleared a Tom Eaves header off the line entering stoppage time but Brentford clung on.