Mile Jedinak's 89th-minute goal for Crystal Palace sent Peterborough to npower Championship relegation.
- Related Content
The Posh, who began the day one place above the relegation zone, were just minutes away from safety until Jedinak popped up at the death to win it for Palace and send their visitors into the bottom three owing to Barnsley's 1-1 draw at Huddersfield.
The game appeared to be heading for a 2-2 draw as Posh goals from Lee Tomlin and Nathaniel Mendez-Laing were cancelled out by Glenn Murray and Kevin Phillips.
Tomlin broke the deadlock in the 28th minute when he curled in from the left and after Murray levelled from the spot, Mendez-Laing restored their lead with a similar effort in the 63rd minute.
Veteran Phillips jangled the nerves when he struck from the edge of the area with seven minutes remaining before Jedinak had the final and fatal say.
It was heart-breaking for Peterborough as it was just their second defeat in the last 13 games and ends a two-year stay in the second tier.
For Palace, it was their first victory in nine and confirms a play-off place, with a two-legged semi-final against Brighton next week.
It was a strong start by Palace and Peterborough were grateful to Grant McCann for saving their skin after 11 minutes.
Damien Delaney's header was parried by Posh keeper Bobby Olejnik and Murray looked poised to end an eight-game drought when he got on the end of the rebound, but McCann heroically cleared the ball off the line.
With news filtering through from West Yorkshire that Barnsley were winning at Huddersfield, it meant Posh dropped into the bottom three and they had to up the ante.
They responded well and Mendez-Laing fired an effort just past Julian Speroni's post before they crucially took the lead in the 28th minute.
Tomlin picked up the ball on the left hand side, went on a surging run, beating three players and curling through a crowded box into the bottom corner.
But their relief was short-lived as Palace levelled in first-half stoppage time. Daniel Gabbidon was fouled by Gabriel Zakuani following a corner and Murray finally got back on the scoresheet by despatching the resulting penalty.
In a dramatic afternoon, things swung in Peterborough's favour again shortly after the restart as Huddersfield levelled to send Barnsley back into the bottom three, but Ferguson's men were living dangerously.
Murray was close to doubling his tally following good work from Wilfried Zaha, but Tommy Rowe superbly cleared the ball off the line.
But just after the hour mark, Posh took their destiny back into their own hands as they regained their lead. Mendez-Laing cut in from the right and curled an effort that bounced just in front of Speroni and nestled in the bottom corner, with the Palace keeper disappointed not to do better.
With the game at Huddersfield progressing to 2-2 it looked as if Posh would be safe, though their nerves were jangled when Phillips struck from 18 yards to also level at 2-2.
But the decisive moment came with just a minute of normal time remaining when Jedinak headed home Stephen Dobbie's cross to break Peterborough hearts and end Palace's barren run.