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."
Doncaster 33 Woods 02 O'Connor 03 Friend 11 Lockwood 41 Beye Dismissed 16 Oster (Hird - 59' ) 17 Barnes 18 Gillett 26 Coppinger 09 Brown (Dumbuya - 73' ) 22 Robert (Hayter - 46' ) Substitutes 01 Sullivan 21 Hird 24 Dumbuya 12 Hayter 23 Bennett Portsmouth 01 Ashdown 02 Ward 03 Rocha 05 Pearce 15 Halford 23 Rekik (Futacs - 76' ) 16 Allan 19 Norris 11 Varney (Harris - 46' ) 14 Etuhu (Kitson - 28' ) 22 Maguire Substitutes 04 Mokoena 17 Harris 09 Futacs 18 Kitson 24 Scapuzzi