Portsmouth 2 Sunderland 1: Matthew Taylor drove home an 88th-minute penalty after Sunderland striker Kevin Kyle handled in the area to help Portsmouth climb out of the Premiership relegation zone.
Svetoslav Todorov made up for a couple of misses with Portsmouth's 72nd-minute equaliser less than three minutes after Tommy Miller had given relegated Sunderland a shock lead at Fratton Park.
The late goals keep Harry Redknapp's team in the running to beat the drop after rivals Birmingham drew at Everton, and West Brom lost at Newcastle.
Lomana LuaLua missed a third successive match with his damaged foot and midfielder Pedro Mendes was also out with a thigh injury for Portsmouth. But the home side were able to recall skipper Dejan Stefanovic in defence.
The already-relegated Black Cats represented a bigger threat on recent away form which has seen them pick up points against Manchester United and Everton, and Pompey boss Harry Redknapp had already expressed his fears they were still playing for Premiership pride.
The visitors brought striker Kyle into the starting line-up. Sunderland made a bright start and forced two corners but it was Gary O'Neil's shot at the other end which produced a mighty shout for a penalty when it bounced off a defender. Referee Mike Dean ignored the claim.
Portsmouth survived another scare when Miller's powerful drive proved too hot for goalkeeper Dean Kiely to hold, but when the rebound came to the feet of Jon Stead he was unable to take it under control.
Full-back Brian Priske went close for Pompey when his shot was blocked for a corner but their pressure was being met by some stern resistance from the Black Cats.
In the 40th minute it looked as Benjani Mwaruwari had made the vital breakthrough. Taylor fired in from the left flank and the Zimbabwe striker stuck out a leg to divert the ball - only for it to bounce away off the goalkeeper.
Three minutes later, Mwaruwari was shooting for goal again but again his effort was blocked, this time by defender Danny Collins.
Portsmouth badly needed a bright start to the second half and had a wonderful opportunity to go ahead in the 48th minute.
O'Neil's pass sent Todorov streaming clear from just inside the Sunderland half but he could not beat keeper Davis with his one-on-one attempt.
They almost paid heavily for the lapse four minutes later when Julio Arca raced away down the left in an overlapping run for Sunderland and provided a superb cross beyond Kiely which Priske kept out as striker Chris Brown closed in.
Gary Breen was booked for a foul which took out O'Neil but the free-kick by D'Alessandro provided an easy save for Davis.
Todorov failed to convert another splendid opportunity in the 62nd minute. Davis saved Sean Davis' 20-yarder but could not hold on to it and Todorov looked certain to tap in the rebound - only for the keeper to bravely smother his effort from three yards.
However, it was the visitors who took the lead in the 70th minute against the run of play.
Miller broke away passing to Arca on the left and although the Argentinian's first cross was cut out, his composed cutback presented Miller with an open goal and he converted from four yards.
The lead lasted just three minutes as Todorov made amends for his previous misses with a powerful finish for the equaliser after Sunderland's sluggish defending had given him time to turn in the area.
Sunderland could have scored again on the break before Kyle's aberration but Taylor drilled home from the penalty spot to snatch victory after the Sunderland striker was judged to have handled in the area following a corner.