Oldham produced a dramatic late comeback to earn the three points which lifted them above Barnsley near the foot of the Coca Cola League One table.
The Latics looked beaten as stoppage time approached but goals by substitute Scott Vernon and New Zealand international Chris Killen left the visitors stunned and beaten.
Barnsley had already wasted an early chance when they went in front in the 12th minute through recalled striker Michael Boulding.
His first shot was saved but he scored with his shins from six yards out when he charged down David Beharall's attempted clearance.
Barnsley then hit the post through Paul Reid but they were pegged back to 1-1 when a flowing Oldham move ended with Killen side-footing home from close range after a low cross by winger Lee Croft.
The chances came and went at both ends but it was Barnsley who created more of them only to be frequently denied by home keeper Leslie Pogliacomi.
Oldham veteran David Eyres forced a good save at the other end when he let fly from 35 yards but the visitors went back in front from a corner.
Defender Matt Carbon met it powerfully with his head and the effort was deflected in by Michael Chopra who was stationed on the line.
Croft missed a chance for Oldham but they looked dead and buried until Vernon got on the end of Will Haining's throw-in to nod in from six yards.
The winner came less than a minute later as Neil Kilkenny curled in a corner form the left and Killen met it perfectly with a close-range header.