Rejuvenated Reds cruised to what appeared an unassailable 3-0 lead, but two quick goals from the U’s made for a frantic finish.
The Reds were dominant in the first half and deservedly led 2-0 at the break.
The visitors went close when captain Alfie Mawson saw his thumping header superbly saved by Jamie Jones, with the rebound falling to Adam Hammill, who curled a shot inches past a post.
Conor Hourihane opened the scoring on 18 minutes, slotting home his seventh goal of the season from close range after Sam Winnall had initially been forced wide by goalkeeper Jones.
Five minutes before the break the lead doubled when Winnall rolled a perfect pass to Hammill, who crashed home his third goal since returning to the Reds.
The U’s started the second half purposefully, Tom Eastman nodding against the crossbar before Richard Brindley fired wide.
The Reds weathered the mini-storm before forging their way further clear on the hour mark. Ivan Toney made it 3-0, heading home his second goal in as many games as he met Marley Watkins’s smart cross.
The U’s pulled one back in the 67th minute, George Moncur slotting past Adam Davies and Chris Porter smashed home to make it 3-2 with 20 minutes left.
Marvin Sordell and Porter went close towards the end, but the Reds hung on.
Colchester United: Jones; Brindley, Eastman, Elokobi, Briggs; Gilbey, Edwards; Massey, Moncur, Harriott; Sordell. Unused substitutes: Parish, Vincent-Young, Kent, Szmodics, Lapslie, Bonne, Porter.
Barnsley: Davies; Wabara, Nyatanga, Mawson, White; Watkins, Pearson, Hourihane, Hammill; Winnall; Toney. Unused substitutes: Townsend, Roberts, Williams, Isgrove, Bree, Jackson, M Smith.
Referee: Stephen Martin (Staffordshire).