It looked worrying for the visitors when they fell behind to Scott Fenwick’s close-range effort.
But Keith Lowe headed in Josh Carson’s corner, before converting Russ Penn’s cross.
Jake Hyde secured victory - which puts York six points clear of the drop zone - with a long-range finish.