Andy Holt headed the Cobblers in front just before half-time before Tom Craddock levelled early in the second half when he turned the ball home from close range with Town appealing for offside.
But Leon McKenzie grabbed the winner - with his seventh strike in just 11 starts - when he headed home a cross from the impressive Holt.
Sampson said: "It was a great derby, especially in the second half, and the players showed great spirit to come back and win it after their equaliser. We always fancy our chances to score from set-pieces if the delivery is right because we've got players who are dangerous in those situations.
"They equalised from what looked to be an offside position. If that goal had changed the outcome of the game we wouldn't have been happy.
"We've got to keep our home form going and try and pick up some points on our travels as well."
Source: PA
Source: PA