Grant Leadbitter scored a 93rd-minute penalty as Middlesbrough beat QPR to go third in the Championship.
The Boro captain sent Robert Green the wrong way from the spot after Leroy Fer handled Daniel Ayala's shot on the line and was sent off.
It was tough on Rangers, who defended resolutely and looked set for a point.
Boro had struggled to create openings, although David Nugent turned Albert Adomah's cross onto the post with their best first-half chance.
Victory lifted them above Burnley and to within a point of leaders Hull City.
Rangers, who were without interim head coach Neil Warnock for personal reasons, have now lost five successive away games and have failed to score in their last four fixtures.
Boro should have gone in front when Nugent could only flick Adomah's cross on to the post and back into the arms of keeper Green.
Fer shot straight at Dimi Konstantopoulos and Matt Phillips missed his kick when in on goal as Rangers started the second half brightly, while George Friend and Stewart Downing drove wide for Boro.
However, the game was settled in stoppage time when Fer flung out his arm in front of Green to block Ayala's shot and Leadbitter slotted in the spot-kick for his 50th career goal and second of the season.
Middlesbrough boss Aitor Karanka told BBC Tees:
"I think it was an amazing game, I am really proud of my players.
"It was a big test after the defeat by Hull. We played a really good team, we were playing a recently relegated team and my players showed we had personality. It was really difficult to play with this atmosphere.
"They had everything clear and trusted themselves. It's an important goal because it was three more points, but the main thing is the way we have won, we never panicked even at 90 minutes."
QPR interim assistant boss Kevin Blackwell told BBC Radio London:
"Sometimes in life you don't get out what you put in, and the lads tonight did not.
"Their endeavour, work-rate and smartness, they stuck to their game-plan and Middlesbrough couldn't deal with it.
"In the second half we had five great chances, it's frustrating one of those didn't go in. I feel for the players because as a manager if you come off and say to them you've given me everything and lost you can't argue, and I can't argue."