City won for the first time in 13 games but are still nine points adrift of safety with nine available - and have a goal difference 11 inferior to third-bottom Newport.
Bradley Fewster headed York ahead, Lewis Alessandra hit a low shot and Luke Summerfield scored from 30 yards.
Gareth Evans got Portsmouth's goal after a mistake from Scott Flinders.
The defeat leaves Pompey in sixth place, five points clear of eight-placed Wycombe. They could secure a play-off place this weekend.
York, meanwhile, will be relegated if they do not beat second-placed Accrington on Saturday. They could also be relegated with a win if other results do not go their way.
York City manager Jackie McNamara told BBC Radio York:
Media playback is not supported on this device
"I thought we were excellent to a man. If anything we could have had another three or four goals.
"The players did everything we asked of them.
"The ability has always been there but the mindset has been the big problem."
York beat Portsmouth to keep alive their very slim chances of avoiding relegation from the Football League.