A second-half strike from Darryn Stamp secured three valuable points for Northampton in a battle of the second division strugglers.
But while they were delighted, it proved to be a poor New Year's Day for the home side and their caretaker boss Glyn Hodges in particular.
The defeat could well cost him the chance of landing the manager's job at Oakwell full time.
After a scrappy opening period in which Bruce Dyer was denied a penalty when he went over in the box, the home side took the lead in the 24th minute with their first shot on target.
Rory Fallon did well to find Kevin Betsy wide on the right and, when his low cross was dummied by Dyer, there was midfielder Chris Lumsdon to fire home right-footed with the aid of a slight deflection.
After 32 minutes Dyer was clearly pulled back by the last defender and the assistant referee immediately flagged, but referee Lee Mason ignored his better-placed colleague and waved play on.
And that proved to be a big moment as Northampton drew level in first-half stoppage time.
Midfielder Paul Harsley was allowed to cut in from the right and his left-foot shot took a massive deflection off the unfortunate Lumsdon and flew into the opposite corner to Andy Marriott's dive.
Despite the ever-willing Alex Neil giving his all in midfield, Barnsley were poor in the second half and were undone in the 69th minute after a comedy of errors at the back.
Mike Flynn's attempted clearance went straight to Stamp and he smashed a volley past the helpless Marriott.
Barnsley piled on the pressure in the closing stages and substitute Mike Sheron saw his last-minute shot saved at the post, but the defeat leaves the home side anxiously looking over their shoulder.