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."
Rochdale 01 Lillis 03 Bennett 04 Cavanagh 05 R Edwards 12 P Edwards 14 McIntyre Booked 07 Kennedy (Grimes - 79' ) 08 Tutte 15 Adebola (Donnelly - 46' Booked ) 22 Grant 27 Gornell Substitutes 31 Smith 02 Rafferty 19 Pearson 06 Barry-Murphy 11 Grimes 23 Craney 09 Donnelly York City 24 Ingham 04 Smith Booked 06 Parslow 16 Fyfield 23 Doig 08 Kerr 17 Blair 19 Potts (Challinor - 85' ) 26 McLaughlin (Oyebanjo - 85' ) 09 Walker (Reed - 89' ) 10 Chambers Substitutes 01 Musselwhite 02 Oyebanjo 03 Blanchett 05 McGurk 20 Challinor 29 Kelly 07 Reed