Harrison Biggins got the home side off to a great start, scoring his first goal for Fleetwood against his old club.
The Tykes released the midfielder when he was a teenager, Biggins then following a similar route to that of Jamie Vardy from Stocksbridge Park Steels to Highbury.
He popped up with a poacher's finish the forward would have been proud of, stroking home James Husband's sublime cross from the left after good hold-up play by Ched Evans on the wing in the 19th minute.
But Barnsley fought back, exploiting some poor Fleetwood defending. Firstly Ash Eastham was out-muscled by Jacob Brown in the 32nd minute as he pounced on an Alex Mowatt chip.
Kieffer Moore completed the turnaround three minutes before the break as the forward out-foxed Town sub Cian Bolger and drilled the ball into the bottom corner.
Fleetwood pressed for a leveller in the second half but Barnsley held firm with right-back Lewie Coyle going closest for Town at the death as his first time effort was kept out.
But it was Barnsley who were to get that late goal, Mamadou Thiam catching Town on the counter and curling the ball past Alex Cairns in injury time.