Two first-half goals from Michael Potts and one by Jason Walker saw York defeat play-off chasing Rochdale.
Potts pounced to score from close range before Walker toe-poked the ball past Josh Lillis to double their lead.
Potts bagged the third when he clipped the ball past Lillis.
Rhys Bennett pulled one back after weaving past several defenders and slipping the ball home before Bobby Grant scored a late penalty following Potts's foul on George Donnelly.
VIEW FROM THE DRESSING ROOM
York City manager Gary Mills told BBC Radio York:
"I think it was about getting the win, no matter how we got it we've needed that, I think we've deserved it.
"We kept saying, if we take our chances, sooner or later someone's going to be down three or four at half-time and it's happened today against Rochdale.
"I thought it was very even second half but overall we've deserved the victory."
Sorry, we were unable to load match stats, please try again.