Thomas Frank's side fell behind in the opening minutes when Brentford goalkeeper David Raya fumbled Neeskens Kebano's cross into his own net to put Middlesbrough ahead.
But Brentford was level in the 38th minute when Ivan Toney tapped in after good work by Tariqe Fosu.
Vitaly Janelt fired home from the edge of the area in the 58th minute after top scorer Toney had headed the ball down for him.
Mathias Jensen made it 3-1 after a slip from centre back Paddy McNair in the 64th minute, before Toney tapped in the fourth 10 minutes from time.
Brentford is just one point behind leader Norwich City and holds a game in hand.
Sixth placed Bournemouth ended their its poor run with a 3-2 home win over Birmingham City, with former Arsenal star Jack Wilshere scoring one and setting up another for the hosts.
Birmingham was ahead in the 27th minute when Asmir Begovic spilled a Gary Gardner cross and Scott Hogan finished from close-range.
Wilshere set up Arnaut Danjuma to level in the 36th minute and headed the Cherries ahead just past the hour mark.
Although Hogan headed an equaliser seven minutes later, Bournemouth's Philip Billing tapped in unmarked at the far post with 13 minutes remaining.
Curtis Nelson and Kieffer Moore got Cardiff City's goals in the 2-0 win at Bristol City to hand manager Mick McCarthy his first victory since taking charge.
Millwall came from behind to thrash lowly Sheffield Wednesday 4-1 at The Den.
Callum Paterson gave Wednesday a 10th-minute lead, but Kenneth Zohore's 39th-minute penalty levelled things up.
Scott Malone, Ben Thompson and Tom Bradshaw completed the rout.
New signing Glenn Murray impressed for Nottingham Forest in the 3-0 win at bottom club Wycombe Wanderers.
Murray lobbed the opener in the seventh minute and doubled the lead nine minutes into the second half from the penalty spot.
Anthony Knockaert wrapped up the points in the 72nd minute.
Yoann Barbet's 54th-minute goal gave Queens Park Rangers a 1-0 win against Blackburn Rovers.
Rotherham United climbed out of the relegation zone with a 2-1 win at Preston North End, while Luton Town drew 1-1 with Huddersfield Town.
Coventry City and Watford shared a goalless draw, with Stoke City and Reading also playing our a 0-0 stalemate.
Barnsley's match against Derby County was postponed because of heavy rain.