York's Jason Walker scored the only goal of the game to inflict a fourth successive defeat on Accrington.
The forward fired a bobbling ball past Ian Dunbavin with seven minutes to go to make it back to back victories for City.
In the first half York were looking to catch out a Stanley side who had conceded 11 goals in their previous three games.
Matty Blair's 20-yard strike was not far off while Walker's effort was blocked by George Miller.
City appealed that Clarke Carlisle's scrambled shot was over the line as Dunbavin dived low but referee Darren Drysdale waved away any appeals.
At the other end Lee Molyneux had a cross finger-tipped over by keeper Michael Ingham while Padraig Amond should have done better with a free header which he steered off target.
In a lively end to the half, Dunbavin kept out Blair's deflected blast from 18 yards and when Walker burst through Dunbavin denied him and the keeper needed Dean Winnard to get back and hook the ball off the line to keep it goalless at the interval.
After the break Blair broke through and passed to Ashley Chambers but the shot was blocked while a Danny Kearns volley was not far off after 65 minutes.
York were creating the better chances but it looked like it would peter out to a goalless draw until Walker finished a scrappy move and earned his side the three points.