Jamal Fyfield's injury-time winner fired York back into the play-off places with victory over promotion rivals Grimsby Town.
City opened the scoring through Jamie Reed's 20-yard effort and doubled their lead when Chris Smith slotted home Patrick McLaughlin's corner.
Anthony Elding and Michael Coulson scored headers to bring the Mariners back onto level terms.
But Fyfield's 25-yard effort after 92 minutes decided the game.
VIEWS FROM THE DRESSING ROOM
York City manager Gary Mills told BBC Radio York:
"I know they scored two goals but I think that's the best we've played. We've played well in some games this season but that was the best for us.
"I know you can say we conceded two goals, which we're disappointed with, but it would have been an absolute travesty not to go home with three points.
"It was a massive three points and we've got it. Three goals away from home, particularly at Grimsby, I'm delighted for everybody."
Grimsby Town joint-manager Paul Hurst told BBC Radio Humberside:
"I thought we started extremely well but gave away a sloppy goal.
"York showed a lot of quality and we had to hang on in at times.
"When it went to 2-2, I thought the little bit of difference was that they knew where to put the ball to just take the sting out of it slightly.
"Maybe that final bit of quality was missing on our side."