Sunderland threw away a two-goal lead before Wes Brown's dramatic late strike gave them victory over QPR.
The Black Cats went ahead through Nicklas Bendtner's header and doubled it shortly after half-time through Stephane Sessegnon's breakaway goal.
Rangers responded through Heidar Helguson's close-range finish and Jamie Mackie's header within the space of four minutes.
But Brown's header snatched the win with two minutes remaining.
New Sunderland boss Martin O'Neill had called for greater ruthlessness from his team but would not have expected Brown to be the man to earn him a second win in three matches in charge.
The former Manchester United defender had not scored in the Premier League since October 2008 but his late effort secured only a fourth league win of the season for the Black Cats.
It is a victory that will have O'Neill looking up to mid-table after starting the day only three points above the relegation zone.
Rangers have managed only one win at Loftus Road all season, but boss Neil Warnock would surely have been satisfied with a point after a battling second-half performance.
They now head to Swansea and Arsenal over the festive period as they attempt to stay out of trouble.
QPR were determined to give themselves some breathing space ahead of the festive programme but, other than a series of Joey Barton set-pieces, they struggled to test the Sunderland defence in the opening period.
Bendtner had already gone close when a Sebastian Larsson free-kick was flicked on by John O'Shea and the Danish striker's glancing header came back off the inside of the post.
But he put the visitors ahead after 14 minutes when he evaded marker Matt Connolly to head in from Kieran Richardson's corner for his third of the season.
As Sunderland continued to look dangerous on the break, Richardson drove a swerving shot past the post from 25 yards.
The hosts finally made a decent opening when Armand Traore's cross was met by Helguson's powerful header, which was cleared off the line by Titus Bramble shortly after half-time.
Just over a minute later, Sessegnon latched on to Danny Gabbidon's loose header to race clear before waiting for Paddy Kenny to commit himself and producing a calm finish.
But the home side pulled one back just after the hour, when Helguson nudged ahead of Brown to prod in Traore's cross.
Shortly afterwards, Alejandro Faurlin's clipped cross was headed down by Helguson for Mackie to score a second with a diving header.
After that, Sunderland created the majority of the chances, with Craig Gardner forcing a smart save from Kenny.
But with only just over a minute left, Brown's glancing header from Richardson's corner had enough power to beat the despairing attempted clearance of Faurlin.
QPR manager Neil Warnock: "I've never felt so disappointed. The lads were fantastic but all three goals were very poor. I don't want to go into them publicly.
"They got out of prison. You can accept losing to the better side and fantastic goals but we were the better side and the goals were poor.
"We've had so many blows, daggers in the heart, but I'll sort it out in January."
Sunderland manager Martin O'Neill:"There's still plenty of work to do and the players accept that. We're delighted with the win.
"We had a great response and at 2-0 we were in a great position but we won the game twice.
"It's pleasing. It hasn't cured all our woes but we're delighted."