David Hunt struck the second-half winner as Northampton continued to climb the table.
The hosts created enough chances to have won by a bigger margin but Mansfield keeper Kevin Pressman was in top form, pulling off a string of outstanding saves to keep his side in contention.
Northampton dominated the game from start to finish and injury-hit Mansfield were on the back foot for long periods.
Pressman kept out a header from Scott McGleish after only five minutes and then followed up with a smart save to deny Jason Crowe after a quick break.
Eoin Jess then tested Pressman, who then denied former Mansfield striker Junior Mendes late in the half. In between Josh Low had a shot deflected wide while McGleish fired over.
The Stags created a couple of chances and Jonathon D'Lareya saw a shot blocked, while loan striker Allan Russell headed just over.
Pressman continued to frustrate Northampton after the break, saving from Jess once again while McGleish headed wide and then somehow flicked the ball on to the top of the bar from close range.
Finally, Hunt came up trumps in the 66th minute when his 20-yard free-kick curled into the top corner with Pressman for once beaten.
The veteran shot-stopper denied Low a certain second goal moments later, before substitute Nathan Arnold almost grabbed an unlikely point for the visitors when he headed straight at home keeper Lee Harper in the 80th minute.