Having lost at Gateshead in the week, Gary Mills’s side responded in the perfect manner to claim three points and move up to seventh place.
They are just four points off the top of the league.
York broke the deadlock on 52 minutes at Edgeley Park, against a Stockport side who had drawn eight of their 12 games this season under Dietmar Hamann.
Matty Blair gave York the lead.
And top scorer Jason Walker sealed the points with a goal four minutes from time.
It was the summer signing’s 10th goal of the season and a fourth consecutive game in which he has scored.
Michael Paton’s 90th-minute goal was no more than a consolation for Stockport.
For the full report and reaction read Sports Monday, free inside Monday’s Yorkshire Post.