York moved up to third position in the Blue Square Bet Premier table with victory away to Hayes and Yeading.
Jason Walker scored his 15th goal of the season with a curled free-kick from 20 yards and Jon Challinor doubled the visitors' lead with a drilled low shot.
Louie Soares headed Hayes back into it but Patrick McLaughlin's calm finish restored York's two-goal advantage.
Substitute Adriano Moke set up Ashley Chambers for the fourth before Luke Williams' consolation from 20 yards.
VIEWS FROM THE DRESSING ROOM
York City manager Gary Mills told BBC Radio York:
"I thought we were excellent with the football. We've come here, it's not easy and I thought in the first half an hour we were very good.
"We know the down side. We're talking about a team here that scored four goals but we've conceded two.
"We've got to cut them out and we keep talking about that. But as for the other side of it, moving the ball, passing the ball and creating chances, it's a fantastic three points."