It was York’s first win since the opening day of the season, and they were given a helping hand by John Sullivan who spilled Josh Carson’s free kick for Wes Fletcher to net, before gifting Lewis Montrose a tap-in.
In between Pompey had levelled briefly through Jed Wallace.
It was the start of three goals in six second-half minutes, as Ryan Jarvis fired into the corner and Fletcher headed a fourth goal. John Marquis grabbed a Pompey consolation.
Victory lifts York three points clear of the League Two drop zone.