Portsmouth confirmed Doncaster's relegation from the Championship while saving themselves by scoring twice in stoppage time in an amazing turnaround.
Trailing 3-2 to 10-man Doncaster in the 90th minute, Dave Kitson and Marko Futacs struck to save Pompey for now.
The hosts led via early Habib Beye and Fabien Robert strikes but when Beye saw red for a foul on Kitson, Greg Halford scored the first of two penalties.
James Coppinger made it 3-2, before the visitors' barely believable late rally.
Even so, Pompey's chances of staying in the division are slim, as they are seven points from safety with three games left.
But they will be delighted to at least give themselves a chance, while Doncaster may well feel harshly treated.
A chaotic game turned on the questionable dismissal of former Senegal international Beye on the hour.
Kitson fell theatrically under pressure from the veteran Senegalese to give away a penalty and controversy also surrounded the Pompey substitute's late leveller as it appeared he handled the ball.
The amazing end to the game left the home fans hooting their disapproval.
By contrast the few hundred travelling Pompey fans remained behind singing in celebration after the whistle.
Michael Appleton's side got off to the worst possible start when Beye headed in from a free-kick, before Robert stabbed home from close range after John Oster's initial effort had been blocked.
That brought a change from the Pompey boss before the half-hour, with Kitson replacing Kelvin Etuhu.
And after showing some signs of life in the second half, the visitors were then given a hotly contested penalty as Beye was dismissed for denying Kitson a scoring opportunity.
Doncaster's James O'Connor was penalised soon after, with Halford tucking in from 12 yards again, before Coppinger put Doncaster ahead once more via low shot.
Dean Saunders's were hanging on before Kitson made it 3-3 and when Futacs slid in the winner, it ended Doncaster's four-year stay in the division.
Doncaster Rovers chairman John Ryan: "I thought the officials today were an absolute disgrace. I will be speaking to the head of referees tomorrow.
"I thought it was a clear handball for the third goal and a clear handball for the fourth goal. The first penalty I thought was outside the box.
"I'm absolutely sickened to the core about the standard of refereeing."
Portsmouth manager Michael Appleton: "Our chances of staying up are not great.
"Even if we win the three games, all Bristol City have to do is look after their own ship. I think if it was a Grand National we'd be a 500-1 shot.
"What today does do though is it gives me confidence we can win three games."