Substitute Ryan Hedges was the hero at rain-soaked Oakwell as his brilliant late strike sunk gutsy Morecambe.
The Reds laboured to their Carabao Cup first round victory against League Two opposition who just wouldn’t lie down.
The visitors rallied from 3-1 behind to make it 3-3 late on, leaving Hedges to finally sealed the hosts’ passage in the final minute of added time.
Boss Paul Heckingbottom breathed a sigh of relief when Hedges expertly curled home with seconds remaining.
The Reds - who featured three changes to the side beaten at Bristol City - enjoyed a perfect start to the game by opening the scoring inside two minutes.
It was a beautiful team strike, with George Moncur and Ike Ugbo combining to free Tom Bradshaw, who slotted home from just inside the box.
The Reds were dominant early on, with both the recalled Adam Hammill and Bradshaw going close to doubling the lead. Finally Jim Bentley’s Shrimpers created their first opportunity came in the 18th minute when Andrew Fleming lashed a shot narrowly over the top.
The response didn’t last long, however, and the Reds doubled their lead four minutes later.
This time Ugbo, after charging down the flank, drilled in a low cross which ex-Doncaster defender Mitchell Lund could only force into his own net from close range.
It was almost 3-0 when Bradshaw found space again in the box, only to fire a shot straight at Aussie ‘keeper Danijel Nizic. Hammill then curled inches over after a smart knock-down from Bradshaw.
The visitors shocked Oakwell when they grabbed a lifeline in first-half stoppage-time. Sam Lavelle crashing home.
The Reds restored their two-goal advantage just 23 seconds into the second period.
Bradshaw was there again, heading home his second goal of the night as he met Hammill’s perfect cross.
Some home fans must have thought the Reds were in cruise control, but gritty Morecambe made it 3-2 just three minutes later when Micheal Rose slotted home from the spot.
Rose was again at the heart of the action soon after when his curling free-kick came within a whisker of making it 3-3.
Back came the Reds, and Bradshaw fluffed a hat-trick chance when he fired horribly wide from inside the box.
Brad Potts and Ugbo were then denied by a frantic double block as the Reds pushed frantically for a fourth goal.
Sub Stefan Payne almost made an immediate impact just minutes after he hopped off the bench to replace Ugbo.
He slid in bravely to meet Moncur’s low driven cross, but couldn’t direct his effort on target.
Vadaine Oliver slid in to make it 3-3 with eight minutes to go, only for Hedges to then produce his late, late victory stunner.
Barnsley (4-4-2): Davies; Pearson, MacDonald, Pinnock, Yiadom; Potts (Mowatt, 86), Moncur, Williams (Hedges, 86), Hammill; Ugbo (Payne, 77), Bradshaw.
Subs not used: Townsend, McCarthy, Jackson, Mallan.
Morecambe (4-3-3): Nizic; McGowan, Kenyon, Fleming, Brough; Campbell (Thompson, 69), Lund (Ellison, 50), Rose; Lavelle, Turner (Deakin, 74), Oliver.
Subs not used: Roche, Conlan, Wildig, Brownsword.
Referee: Darren Bond (Lancashire).
Star man: Adam Hammill.