A sweeping move between Joss Labadie and Graham Coughlan carved the Cobblers defence apart for Jake Robinson to tap in from close range for his fourth goal of the season.
But only resolute defending denied Northampton before half time as Labadie cleared off the line, Steve Guinan hit the side netting and Ryan Gilligan blazed over from 15 yards.
The visitors also started the second half well, but two identical goals in five minutes killed them off.
Kevin McIntyre floated free-kicks to the far post from almost the same spot on the pitch for first Labardie and then Kelvin Langmead to head home past the visitors' static defence.
Gilligan hit the post in stoppage-time and Luke Guttridge twice tested Steve Phillips but the on-loan Bristol rovers keeper kept his third clean sheet in a row.