Summer signing Ryan Jarvis struck on his league debut to seal the points for the Minstermen with a last-minute header, while Darren Carter was sent off in the second half for two yellow cards.
York began the brighter, with Ashley Chambers forcing Cobblers goalkeeper Matt Duke into a full-stretch save following Richard Cresswell’s through-ball after five minutes.
Northampton responded with their first chance on the half-hour mark as summer signing Danny Emerton dragging his shot wide after Lanre Oyebanjo’s loose ball fell into his path.
Both sides traded chances immediately after the restart with Chambers shooting wide at the far post before Ray O’Donovan beat York defender David McGurk for pace only to see his effort crash against the underside of the crossbar and bounce away.
The Cobblers were reduced to 10 men when Darren Carter collected a second booking for a foul on Ryan Jarvis with 18 minutes remaining.
In the final minute it was Jarvis who was to have the final say as he fired home Cresswell’s knockdown from inside the area.