Ashley Fletcher's poacher's finish in the sixth minute looked to have put Boro on track for a third win in four undefeated games in the race to the Premier League.
But a victory that was very much required because of wins for Norwich, Sheffield United and Leeds was taken away from Boro in the final 20 minutes, leaving them 12 points off the top two.
Defender Ryan Shotton helped Henrik Dalsgaard's drive into his own net after some poor defending in the 70th minute and that was followed by Said Benrahama's winner three minutes later.
It was only Brentford's second away win of the campaign and left Middlesbrough fans questioning Tony Pulis' decision to replace striker Britt Assombalonga with full-back George Friend when they led.
The hosts were never convincing even though Brentford had such a poor away record.
Fletcher rewarded Pulis' recent faith in him by scoring for a second home game in a row to edge Boro ahead.
The former West Ham striker reacted first in the area to force a finish over the line after goalkeeper Daniel Bentley had spilled Mo Besic's low drive from 20 yards.
That opening goal arrived after Middlesbrough midfielder Jonny Howson and Brentford striker Neil Maupay had seen decent lobbed efforts drop the wrong side of the upright.
Brentford then had the better of the chances. In fact they had the ball in the net twice and each occasion referee Jeremy Simpson - who came under-fire from the home fans too - ruled them out.
The first was when Maupay was deemed to be offside as he headed in from eight yards and then the striker was adjudged to have fouled George Saville moments before Sergi Canos powered low into the net.
Canos was the main threat and had two fantastic efforts either side of the break when he must have thought he was going to level things up.
His first was a thunderous drive that crashed against the crossbar and his curling second effort after the interval saw Middlesbrough goalkeeper Darren Randolph turn over with a fantastic one-handed stop.
Boro, whose decision to take off Assombalonga and replace him with the fit-again Friend led to sarcastic chants at Pulis, came within inches of a second when Fletcher headed Shotton's deep cross just wide of the far post.
But Shotton turned into his own net at the other end when Dalsgaard was handed the chance to shoot towards goal after Saville headed weakly away.
Then Brentford took the lead in the 73rd minute. This time Dalsgaard, making the most of freedom down the right, teed up Benrahama in the box to power first time inside Randolph's bottom corner.
Tony Pulis’ side are 12 points off a top-two spot, with Norwich, Leeds and Sheffield United all recording victories.
Pulis was criticised by supporters but was also disappointed with the performance of referee Jeremy Simpson for not giving any of three decent penalty shouts, while Fletcher could have headed in a second.
Pulis said: “We are disappointed. They are a good side, three or four players would be in any team in this division. We got a great start, we should have had a definite penalty.
“I will go and see him (the referee), I don’t normally. He has booked Jonny Howson for diving and the lad has caught him. I don’t know how they get it so wrong sometimes.
“We should have had three definite penalties. At home you think you might get them, or at least one.
“It wasn’t a popular decision (taking Assombalonga off). I didn’t think Britt looked sharp, quite at it like he has been. The Fletcher header I expected Britt to move and tap in, it went past him.
“The whole squad are together, they are in it together. If I bring anyone off I think it is best for team.
“If I messed up, I messed up. People can look at my decisions and say I have made the wrong decision and I have no problem with that.”