Ryan Bowman and a Wes Fletcher penalty won it for Nigel Worthington's side as they completed the double over the Cobblers.
On the back of their first win under caretaker-boss Andy King at Newport, Cobblers began brightly and created several chances. Darren Carter shot wide, Antonio German headed wide and Ishmel Demontagnac saw his low drive saved by Michael Ingham before having another effort blocked.
German had a goalbound effort charged down after Michael Coulson had York's first chance when his effort was blocked.
Lanre Oyebanjo was then denied by Matt Duke who dealt well with his long-range shot.
But Cobblers finished the half back on top with Hallam Hope having a shot blocked and Demontagnac fired wide from the edge of the box. Hope went close from a tight angle shortly after the restart and Danny Emerton fired over while Coulson went close at the other other end.
And it was York who broke the deadlock in the 68th minute when Bowman headed home Josh Carson's cross. Two minutes later York doubled their advantage from the penalty spot after Kevin Amankwaah impeded Coulson and Fletcher converted the ensuing spot-kick.
German and Ben Tozer went close to reducing the arrears and Carter had a shot blocked but the Cobblers remain rooted to the bottom of the table.