Mansfield striker Richard Barker's 22nd goal of the season sent Northampton to only their third away defeat of the season and put a huge dent in their automatic promotion hopes.
In-form Barker, scoring for the third successive game, also ended Mansfield's lingering relegation fears and gave them an outside chance of reaching the play-offs.
The Cobblers, beaten just twice away from home all season and looking to bounce back from a three-goal shock at home to leaders Carlisle, brought in Jamie Hand for the injured Ian Taylor and also gave Jason Lee a start after his impressive substitute's appearance in that Carlisle defeat. Scott McGleish, despite 21 goals in the season, was dropped to the bench.
Roared on by 1,000 travelling fans, Northampton dominated the opening minutes and a Josh Low cross was almost turned in by Sean Dyche.
The Stags struggled to get out of their own half and were twice lucky not to fall behind in the ninth minute. First Andy Kirk broke clear onto a misplaced Stephen Dawson back pass, only to be denied by Kevin Pressman's fine block and Jon Olav Hjelde's clearance.
Then from the resulting corner Pressman dropped Hand's cross and Gareth Jelleyman came to the rescue, hooking the ball off the line.
Four minutes later the keeper spilled another Hand cross, but this time recovered to block Dyche's drive.
As the Stags weathered the early storm, they at last broke clear to create a chance of their own, Laurence Wilson's curling 25-yard drive saved by the diving Lee Harper.
But there was little respite from almost incessant Northampton pressure and in the 39th minute Mansfield were again lucky to survive. Pressman again failed to hold onto a Hand cross and Dyche lashed the loose ball against the underside of the bar, before the linesman waved away long Cobblers' appeals that the ball had crossed the line.
Wilson blasted high and wide from 20 yards at the start of the second half as the Stags still struggled to create chances.
But then a cross-field move involving four players left Dawson with a clear opportunity, but his 20-yard drive flew straight to Harper.
The Stags were now playing with confidence and Barker pulled his drive wide after a fine surging run into the area by Wilson. But he made no mistake in the 65th minute, heading in Gus Uhlenbeek's deep cross after good work from substitute Giles Coke.
Martin Smith scraped the bar with a 25-yard screamer in the 73rd minute as Northampton finally created a chance in the second half, but the Stags hung on for a vital victory.