Middlesbrough took one step towards the Championship play-off final as substitute Fernando Amorebieta scored three minutes into stoppage time to earn a 2-1 win at Brentford.
The defender, on loan from Fulham, proved the unlikely hero in the semi-final first leg, sparing the blushes of team-mate Dimitrios Konstantopoulos after the goalkeeper's howler had handed the hosts a way back into the match.
Jelle Vossen put Aitor Karanka's men ahead in the 26th minute, but Andre Gray pounced on a moment of indecision between Konstantopoulos and Ben Gibson to level after the break.
It looked as though that would be enough to ensure Mark Warburton would earn a draw in his last home game in charge of Brentford - with the club having already confirmed they will appoint a new manager for next season - but Griffin Park was stunned by Amorebieta's superb late strike.
Vossen's precise header capped an impressive opening to the game for Karanka's side, who finished seven points ahead of their opponents.
Gray spurned an excellent chance to level within a couple of minutes of the restart, the former Luton Town man firing over the bar when well placed.
However, he atoned when he chased a seemingly lost cause and blocked Konstantopoulos' poor attempted clearance before finding the net from a tough angle.
Middlesbrough trod a fine disciplinary tightrope, with six players going in the book, which led to some nervy moments late on as Brentford pressed to make their home advantage count.
But it was the away side who provided the final twist, Amorebieta steering home from 12 yards out to ensure Middlesbrough will take a lead back to the Riverside - where they beat Brentford 4-0 in September - next Friday.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.