Steve Claridge scored deep into injury time to claim three points for Portsmouth to keep alive Tony Pulis' hopes of surviving relegation to Division Two.
Nottingham Forest had taken the lead in the 80th minute through Andy Johnson but threw away the chance of victory as they allowed the home side back into the game in a chaotic finale.
There were chances at both ends throughout the game but it needed the introduction of Forest's substitute, Marlon Harewood, to create the first goal.
He burst down the right and beat two tackles using his pace before pulling the ball back for Johnson, who made no mistake, blasting in the opener.
Forest, who lost captain, Riccardo Scimeca to a worrying leg injury in the 66th minute, had lived dangerously all afternoon and slack defending made their lead short-lived.
Portsmouth's Danish midfield player, Thomas Thogersen, equalised in the 84th minute with a flicked header at the near post from a cross by Michael Panopoulos as Portsmouth got back into the game.
Cruelly for Forest, time spent treating Scimeca's injury before he was carried off on a stretcher, proved to be their undoing and four minutes into injury time, Claridge struck a brilliant winner.
The veteran former Birmingham City and Wolves front man picked up the loose ball after a corner, which was flicked on by Adrian Whitbread, then smashed a shot from 15 yards out, which Dave Beasant could not keep out.
It was a fitting reward for Portsmouth, who have dominated the game in the first half, only to be denied by veteran Beasant, who produced brilliant saves to deny Claridge twice and also keep out a header from Lee Bradbury.
Portsmouth substitute Rory Allen was more relieved than most to see Claridge's goal fly in as he made his first appearance for Portsmouth following a seven-month injury lay-off.
The club's £1million record signing had blazed over the cross bar from eight yards out when the scores were still level.

|