Chris Smith's second-half goal fired York to safety as they edged to a dramatic 1-0 victory at Dagenham.
With both sides threatened with the drop ahead of kick-off, Dagenham just about survived too, on goal difference, thanks to London neighbours Barnet losing at Northampton.
Not surprisingly it was a very nervy first half with clear-cut chances at a premium. Dagenham went the closest, creating the three best efforts.
Early on Brain Woodall tried his luck from distance, only for the ball to slide inches wide.
Scott Doe was then unlucky as his brave near-post header from Medy Elito's corner-kick flew into the side-netting.
Billy Bingham went close shortly before the break when his well-struck shot only just cleared the crossbar.
Woodall drew a fine stop from goalkeeper Michael Ingham, before York pounced to score the only goal of a crucial game in the 68th minute.
Smith dragged a shot past Jordan Seabright from 12 yards after latching on to a long punt forward by Ingham.
Seabright saved well from Matty Blair as York almost doubled their lead late on.