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."
Grimsby Town 13 McKeown 02 Silk 15 Pearson 22 Townsend 32 Miller Booked 08 Disley Booked 21 Thanoj (Wood - 50' ) 40 Soares (Duffy - 50' ) 07 Coulson 36 Winn 39 Elding Substitutes 26 I'Anson 19 Wood 12 Duffy 20 Southwell 33 Hughes-Mason York City 24 Ingham 03 Meredith 04 Smith 06 Parslow 16 Fyfield Booked 08 Kerr 17 Blair 20 Challinor Booked 26 McLaughlin 07 Reed 09 Walker Booked (Blinkhorn - 79' ) Substitutes 23 Doig 12 Pilkington 19 Brown 21 Blinkhorn 28 Ashikodi