Two headers from corners gave Cardiff City their first away win in four attempts and took them back to the top of the Championship table.
Teenage defender Ben Nugent marked his first league start with a goal after dispatching Peter Whittingham's corner.
Aron Gunnarsson was then left unmarked at the far post to convert from another Whittingham delivery after the break.
A sweet finish from Jacob Mellis gave Barnsley hope, but Cardiff held on despite Simon Lappin's late red card.
The left-back's dismissal for a second yellow card two minutes before time led to a frantic finish as Cardiff survived two penalty claims and needed two fine interventions from goalkeeper David Marshall.
But time came to their rescue, and left Barnsley to contemplate a fifth defeat in seven games, leaving them one point above the relegation places.
Cardiff end away blues
- Before beating Barnsley, Cardiff had not won a match while wearing blue this season
- The Bluebirds controversially changed from blue to red as their primary colour at the start of the season and have won all nine home games in red
For the 12th time in 18 Championship games this season, Cardiff took the lead.
Nugent wrestled free from his marker and used his 6ft 4in stature to good effect to reach Whittingham's hanging delivery.
The 19-year-old's textbook downward header skipped off the surface past home goalkeeper Luke Steele.
The visitors were twice let off the hook in the first half by poor Barnsley finishing.
Stephen Dawson sliced his volley wide after Cardiff debutant Lappin, on loan from Norwich City, was caught out of position.
And then on the stroke of halftime, unmarked Marcus Tudgay headed weakly wide from a few yards out.
Cardiff were guilty of a glaring miss of their own minutes after the break when Heidar Helguson hit a tame shot from 12 yards, which was turned away by Steele.
But Helguson's blushed were spared by fellow Icelander Gunnarsson as the midfielder headed in at the far post from the resulting corner.
The introduction of Reuben Noble-Lazarus and Akos Buzsaky gave Barnsley much needed-impetus and they capitalised on a purple patch to pull a goal back.
Mellis showed his team-mates how to finish by composing himself and squeezing the ball inside the far post.
Lappin's debut turned sour when he was shown a second yellow card, giving the home side plenty of encouragement to launch a late salvo but they failed to find the telling blow to salvage a point.
Barnsley manager Keith Hill said: "We have let Luke Steele down.
"He has made two match-winning saves and we conceded from both corners and the players are responsible for the individual mistakes they have made.
"The individual errors cost you and that is the difference between the cream and the elite and us at this moment in time."
Cardiff City manager Malky Mackay said: "It was just good to have another three points, coming to a tough ground.
"We were playing against a team that has a fresh influx of players through the week, so we always knew it was going to be difficult.
"I am delighted to come away from here having been clinical and getting the three points.
"We were quite comfortable and in the second half we started really well and on another day could have had another two or three goals had we picked them off on the counter attack."
Sorry, we were unable to load match stats, please try again.