Liam Miller struck deep into stoppage time to hand Sunderland a crucial victory at home against Derby.
Miller climbed high to head home Grant Leadbitter's late cross, flicking the ball beyond Stephen Bywater's reach.
Sunderland had taken the lead when David Connolly scored from the spot after a foul on him by Marc Edworthy.
Giles Barnes scored a stunning solo goal to level, beating two men and firing home, but after Daryl Murphy hit a post, Miller grabbed the winner.
Sunderland boss Roy Keane:
"Right now we're the fourth or fifth best team in the league because that's where we are in the table.
"It was a very close game and it could have gone either way.
"Both teams had chances. It was a great game for the neutral and it was nice to score a goal so late."
Derby manager Billy Davies:
"I thought we deserved to come away with three points."
"I thought we matched them in the first half and then pummelled them in the
second, having about 25 chances to their four.
"I'm sure Roy Keane and his players and the fans of this club are feeling very fortunate tonight."
Sunderland: Ward, Simpson, Nosworthy, Evans, Collins, Edwards, Liam Miller, Yorke, Hysen (Leadbitter 69), John (Murphy 58), Connolly.
Subs Not Used: Fulop, Tommy Miller, Varga.
Booked: Connolly, Collins.
Goals: Connolly 27 pen, Liam Miller 90.
Derby: Bywater, Edworthy, Moore, Mears, McEveley, Teale (Barnes 46), Oakley, Pearson (Michael Johnson 83), Jones, Howard, Fagan (Peschisolido 71).
Subs Not Used: Grant, Macken.
Booked: McEveley, Edworthy.
Goals: Barnes 59.
Ref: M Atkinson (W Yorkshire).