Northampton striker Darryn Stamp capitalised on a defensive error from Barnsley's Mike Flynn to end his side's eight-match losing run with a 2-1 win at Oakwell.
Flynn sliced his clearance skywards and Stamp got to the ball before goalkeeper Andy Marriott to volley a shot into the empty goal from 18 yards.
Barnsley, who have won only once in their last six games, had gone ahead after 24 minutes. Bruce Dyer's cross was left by Kevin Betsy for Chris Lumsdon to drill home a shot from 10 yards.
But the home side were rocked in stoppage time at the end of the first half when Paul Harsley's 25-yard shot deflected off Lumsdon's face and wrong-footed Marriott, making it 1-1.
Veteran striker Marco Gabbiadini wasted a chance to put the Cobblers ahead 10 minutes into the second half when his shot hit the post.
Barnsley surged forward and Dean Gorre's cross was headed off the line by defender Chris Marsh before Stamp sealed the points for the visitors 20 minutes from time.