Stanley's Marcus Carver went close with a header but Stanley made their mark three minutes after the restart.
Midfielder Murphy got the ball from Danny Webber and looped it into the top corner of the net with goalkeeper Phil Smith only able to help it in.
However, after 57 minutes, good link up play saw Agyemang knock the ball down and Connolly finished from close range for the equaliser.
Dunbavin kept out Roman Padovani's strike while Barcham could only find the side netting.
Then Nicky Hunt fouled Connolly in the area 11 minutes from time and the striker dusted himself down and fired home from the spot.
But Pompey's joy was short lived as Kal Naismith's deep cross was headed on by Tom Aldred and Murphy headed over the line from close range five minutes from time.