John Marquis thought he had scored a stoppage-time winner at Accrington, only to then find his own net at the death.
It was a fittingly dramatic end to a crazy Crown Ground contest that at least saw Pompey climb back into the play-off places.
The home side had roared into a commanding interval lead following efforts from Colby Bishop and Cameron Burgess.
But the Blues hit back after the break and Marquis reduced their deficit before substitute Ryan Williams drew them level.
Plenty of chances followed at both ends of the pitch before a fine Marquis finish looked to have completed a remarkable turnaround.
But the striker was in the wrong place at the wrong time, as the ball flew off him and into the net in the final few seconds.
Danny Cowley made one change from the side that saw off Bristol Rovers on home soil at the weekend.
Williams dropped to the bench to make way for James Bolton, which saw former Accrington player Callum Johnson move to the right wing-back role.
The rain was falling heavily when the team arrived at the ground and only got heavier once the game began.
There might have been fears of an abandoned contest – particularly as the last time referee Robert Madley was assigned a Pompey game was at Charlton, which he postponed because of a waterlogged pitch.
It was a high energy opening to the contest, with the action quickly switching from one end of the pitch to the next.
Bolton had to clear when Craig MacGillivray got a palm to Harvey Rodgers’ teasing delivery, while Ronan Curtis then sent a dipping volley past the post.
Johnson came close to breaking the deadlock on 10 minutes away and was inches away from making a connection with a low Marcus Harness centre.
But instead it was the hosts who broke the deadlock soon after, with Bishop meeting a fine Sean McConville cross and heading into the top corner.
It seemed like the Blues would level when Stanley twice failed to clear their lines and Johnson sent the ball towards Marquis in the box.
The striker looked as though he would be left with a simple finish, only for Ben Barclay to slide in and send the ball against the post.
Neither side was letting up as the rain continued to fall, with both trying to take advantage of the conditions by intercepting some wayward passes.
But it was Accrington who finished the half with a flourish and a Dion Charles effort was deflected wide before a fierce McConville strike cannoned off the underside of the bar.
And they did double their lead just before the break after McConville had lifted a free-kick into the mixer.
Bishop turned it towards the goal and the ball might have been crossing the line before Burgess slid in to make sure.
Half Time: Accrington 2 Pompey 0
Cowley made a double change at the break, with Bolton and Ben Close making way for Williams and Andy Cannon.
And Pompey got a lifeline within five minutes of the second half after some sloppy play gifted them possession.
Curtis played a neat pass across to MARQUIS and although his shot was saved by Toby Savin, the ball ran loose for him to lift home a neat finish.
An incredible passage of play then saw Accrington almost restore their two-goal lead before the Blues equalised in controversial fashion.
McConville played a free-kick to Adam Phillips on the edge of the box and his effort was diverted onto the post by MacGillivray.
The keeper then appeared to tip the follow-up header from Rodgers over the bar, only for a goal-kick to be awarded.
And the Blues went straight up the other end to score again, with Curtis and Marquis helping the ball on for WILLIAMS.
The substitute did well to take the ball past Savin and then neatly slotted it into the net to bring the scores level.
Cowley made a third switch just after the hour mark, with Paul Downing making his first league appearance of the season in place of Johnson.
And the fourth quickly followed, as Charlie Daniels was the latest player to enter the fray, with George Byers withdrawn.
Both sides were looking capable of adding to the scoring, with Joe Pritchard firing a good chance over the bar after a McConville free-kick had caused problems.
Pompey then raced up the other end and Williams felt he was fouled in the box by Burgess, but Madley waved play on.
The lively Pritchard soon pulled the ball back for Charles in the box and he sliced another excellent chance wide.
With both sides chasing a winner, the action was becoming stretched and there were plenty of opportunities to launch quick counter-attacks.
Harvey White came on for Harness on 84 minutes, as Cowley made use of his full complement of substitutes.
It was Accrington who almost snatched another goal soon after, though, with MacGillivray fumbling Paul Smyth’s effort and Burgess somehow turning the loose ball against the crossbar.
The keeper was then not able to cling on when McConville squeezed a shot towards the near post, but recovered quickly to keep out the next attempt from Bishop.
But it was the Blues who were celebrating in stoppage-time when White lifted a deep free-kick into the mixer.
Burgess rose to try to head clear, but only succeeded in finding an unmarked MARQUIS, whose acrobatic effort flew into the net.
It looked like that would be enough to seal the points, but McConville then sent a free-kick into the box and when MacGillivray parried away Burgess' attempt, the ball ricocheted off the unfortunate Marquis and flew into the net.
Accrington (4-1-2-1-2): Savin; Rodgers (Smyth 76), Barclay, Nottingham, Burgess; Conneely (c); Phillips, McConville; Russell (Pritchard 68); Bishop, Charles
Goals: Bishop 15, Burgess 43, Marquis 90+5 (og)
Booked: McConville, Conneely, Barclay
Subs not used: Buckley, Perritt, Uwakwe, Morgan, Mansell
Pompey (3-4-1-2): MacGillivray; Bolton (Williams 46), Raggett, Nicolaisen; Johnson (Downing 61), Close (Cannon 46), Naylor (c), Harness (White 84); Byers (Daniels 68); Marquis, Curtis
Goals: Marquis 49, 90+1, Williams 54
Booked: Curtis, Cannon
Subs not used: Ward, Stanley
Referee: Robert Madley