York resisted Rochdale's second half comeback to hang on for a 3-2 victory at Spotland to end a seven-game run without a win.
The visitors were three goals up by the break and took the lead seven minutes in when the Dale defence failed to deal with Jamal Fyfield's cross from the right and after Jason Walker miscued Michael Potts pounced to score from close range.
Walker managed a better connection in the 19th minute when he made the most of more poor defending from Rhys Bennett to toe-poke the ball past Josh Lillis in the Rochdale goal.
Potts bagged the third in the 35th minute after good approach play from Ashley Chambers, picking his way through the hapless hosts' backline before clipping the ball past Lillis.
Terry Gornell had the home side's best attempt of the half just before the break, a curling drive which beat Michael Ingham but thudded against the post and bounced clear.
Dale's comeback started when Bennett pulled one back in the 61st minute, weaving his way round several York defenders before slipping the ball into the net.
And it was game on in the 83rd minute when Bobby Grant fired home from the spot after Potts' foul on George Donnelly.
Dale pushed hard for a winner but Gary Mills' men hung on for the three much-needed points.