Ashley Chambers opened the scoring in the 19th minute on Saturday as he teamed up with Matty Blair before curling the ball beyond Chris Lewington in the Dagenham goal.
York's lead was short-lived as the visitors equalised three minutes later through Luke Wilkinson. The defender met Matt Saunders' in-swinging corner to powerfully head home past Michael Ingham.
Eight minutes before half time, York restored their lead as Chambers added his second of the game. Jamal Fyfield's expert delivery from the left was met by the winger who beat Lewington with a precise header.
On the hour mark Wilkinson was inches away from levelling the scores with his header going the wrong side of the post.
The Minstermen then gave themselves a two goal cushion with 65 minutes gone as Blair stole in at the far post after some great work from Danny Kearns before Wilkinson added a second for the visitors in stoppage time from long range.