Watch highlights of Town 3 Peterborough 4
Watch the match highlights as Shrewsbury Town lose this game but secure their League One status.
Doncaster's 3-1 defeat at Crewe and Blackpool's 4-0 thumping at home to champions Wigan means neither can catch Micky Mellon's side with a game left.
But there was an underwhelming feeling as they had to do it with help from their rivals, after suffering a club record 13th home league defeat of the season.
Town seemed dead and buried after goals from Jack Baldwin (42) and Lee Angol (46 and 69) left them trailing 3-0.
But substitute Jean-Louis Akpa Akpro inspired a comeback by scoring on 74, then setting up headers for Andy Mangan (85) and Jack Grimmer (90).
But former Town winger Jon Taylor came off the bench to grab a dramatic winner in the third minute of time added on.
Midfielder Ian Black was sent off in the fifth minute of stoppage time.