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."
Jacob Mellis gives away a free kick for an unfair challenge on Craig Noone.
Craig Bellamy fouled by Jonathan Greening, the ref awards a free kick. David Marshall takes the free kick.
Free kick crossed right-footed by Akos Buzsaky from right wing, Mark Hudson manages to make a clearance. Akos Buzsaky decides to take a short corner.
Dismissal Simon Lappin receives a red card.
Foul by Simon Lappin on Reuben Noble-Lazarus, free kick awarded.
Booking David Marshall goes into the referee's book for time wasting.
Drilled right-footed shot by Jacob Mellis. Blocked by Mark Hudson. Corner from the left by-line taken by Akos Buzsaky, save by David Marshall.
Direct free kick taken by David Marshall.
Booking Akos Buzsaky is shown a yellow card.
Free kick awarded for an unfair challenge on Craig Noone by Akos Buzsaky.
Jonathan Greening restarts play with the free kick.
Booking Jordon Mutch shown a yellow card.
Free kick awarded for a foul by Jordon Mutch on Craig Davies.
Reuben Noble-Lazarus has an effort at goal. Save by David Marshall.
Substitution (Barnsley) makes a substitution, with Emile Sinclair coming on for Marcus Tudgay.
Effort on goal by Craig Davies from outside the box goes harmlessly over the bar.
Akos Buzsaky takes the inswinging corner, Mark Hudson manages to make a clearance.
Effort on goal by Bo-Kyung Kim from outside the area goes harmlessly over the bar.
The assist for the goal came from Scott Wiseman.
75:35 Goal scored
Goal - Jacob Mellis - Barnsley 1 - 2 Cardiff A goal is scored by Jacob Mellis from just inside the penalty area to the bottom right corner of the goal. Barnsley 1-2 Cardiff.
Substitution Craig Bellamy is brought on as a substitute for Joe Mason.
Effort from the edge of the area by Bo-Kyung Kim goes wide of the left-hand upright.
Unfair challenge on Marcus Tudgay by Ben Nugent results in a free kick. Jonathan Greening delivers the ball, Header from deep inside the penalty area by Marcus Tudgay goes harmlessly over the crossbar.
Substitution (Cardiff) makes a substitution, with Jordon Mutch coming on for Aron Gunnarsson.
Drilled right-footed shot by Rudy Gestede. Luke Steele makes a save. Bo-Kyung Kim has an effort at goal from just inside the box that misses to the right of the goal.
Akos Buzsaky has an effort at goal. David Marshall makes a save.
Shot from 30 yards by Jacob Mellis. Save by David Marshall.
The offside flag is raised against Craig Davies. David Marshall takes the indirect free kick.
Substitution Rudy Gestede joins the action as a substitute, replacing Heidar Helguson.
The assistant referee signals for offside against Craig Davies. David Marshall takes the free kick.
Unfair challenge on Marcus Tudgay by Mark Hudson results in a free kick. Akos Buzsaky restarts play with the free kick.
Peter Whittingham takes the outswinging corner, Unfair challenge on Jimmy McNulty by Matthew Connolly results in a free kick. Luke Steele restarts play with the free kick.
Scott Wiseman challenges Bo-Kyung Kim unfairly and gives away a free kick. Peter Whittingham restarts play with the free kick.
Substitution (Barnsley) makes a substitution, with Reuben Noble-Lazarus coming on for Matty Done.
Substitution (Barnsley) makes a substitution, with Akos Buzsaky coming on for Stephen Dawson.
Aron Gunnarsson produces a right-footed effort from long distance that goes harmlessly over the bar.
Simon Lappin produces a cross, Header on goal by Heidar Helguson from inside the box goes harmlessly over the target.
Assist by Peter Whittingham.
50:26 Goal scored
Goal - Aron Gunnarsson - Barnsley 0 - 2 Cardiff Aron Gunnarsson fires in a goal from close in to the bottom left corner of the goal. Barnsley 0-2 Cardiff.
Heidar Helguson takes a shot from 6 yards. Luke Steele makes a brilliant save. Peter Whittingham takes the inswinging corner,
Jacob Mellis takes the chance to get an effort at goal. Save by David Marshall. Inswinging corner taken right-footed by Jonathan Greening played to the near post, Matthew Connolly makes a clearance.
Matty Done challenges Bo-Kyung Kim unfairly and gives away a free kick. Simon Lappin takes the free kick.
Jonathan Greening challenges Heidar Helguson unfairly and gives away a free kick. Mark Hudson takes the direct free kick.
The referee gets the second half started.
45:00 +1:38 Half time
Half Time The referee calls an end to the first half.
Matty Done fouled by Simon Lappin, the ref awards a free kick. Matty Done produces a cross, Marcus Tudgay produces a header from close range which goes wide of the left-hand upright.
Corner taken right-footed by Jonathan Greening, Foul by Jimmy McNulty on Ben Nugent, free kick awarded. Free kick taken by David Marshall.
Craig Davies has an effort at goal from 20 yards. Save by David Marshall. Corner from the right by-line taken by Matty Done, clearance by Heidar Helguson.
The ball is swung over by Scott Wiseman, clearance by Matthew Connolly. Corner taken by Jonathan Greening from the right by-line to the near post, Marcus Tudgay produces a header from deep inside the six-yard box that clears the crossbar.
Unfair challenge on Craig Davies by Craig Noone results in a free kick. Jonathan Greening delivers the ball from the free kick right-footed from left wing, Matthew Connolly makes a clearance.
The official flags Marcus Tudgay offside. Indirect free kick taken by David Marshall.
Inswinging corner taken left-footed by Peter Whittingham played to the near post, clearance by Marcus Tudgay. Inswinging corner taken left-footed by Peter Whittingham from the right by-line to the near post, clearance made by Craig Davies.
Free kick awarded for a foul by Jonathan Greening on Aron Gunnarsson. Free kick taken by Ben Nugent.
Effort on goal by Stephen Dawson from inside the box misses to the right of the target.
Free kick awarded for an unfair challenge on Craig Davies by Ben Nugent. Shot comes in from Craig Davies from the free kick. Corner taken by Jonathan Greening from the right by-line played to the near post, clearance by Ben Nugent.
Free kick taken by Jimmy McNulty.
Booking Simon Lappin goes into the book.
Free kick awarded for a foul by Simon Lappin on Jonathan Greening.
Joe Mason concedes a free kick for a foul on Scott Golbourne. Free kick taken by Jimmy McNulty.
Assist on the goal came from Peter Whittingham.
21:05 Goal scored
Goal - Ben Nugent - Barnsley 0 - 1 Cardiff Ben Nugent finds the back of the net with a headed goal from deep inside the penalty area. Barnsley 0-1 Cardiff.
Joe Mason takes a shot. Save by Luke Steele. Corner taken left-footed by Peter Whittingham from the left by-line,
Craig Noone has an effort at goal from outside the penalty box missing to the wide right of the goal.
Craig Davies concedes a free kick for a foul on Mark Hudson. Free kick taken by David Marshall.
Shot from 25 yards by Joe Mason. Save made by Luke Steele.
Jimmy McNulty gives away a free kick for an unfair challenge on Joe Mason. Peter Whittingham delivers the ball from the free kick left-footed from right wing, save made by Luke Steele.
Foul by Craig Noone on Craig Davies, free kick awarded. Direct free kick taken by Scott Golbourne.
Jacob Mellis concedes a free kick for a foul on Craig Noone. Strike comes in from Peter Whittingham from the free kick.
Unfair challenge on Heidar Helguson by Martin Cranie results in a free kick. Peter Whittingham takes the free kick.
Effort on goal by Craig Davies from just inside the area clears the bar.
Jonathan Greening produces a right-footed shot from outside the penalty box and misses right.
Jonathan Greening gives away a free kick for an unfair challenge on Craig Noone. Free kick crossed right-footed by Peter Whittingham from right wing, clearance by Scott Wiseman. Outswinging corner taken left-footed by Peter Whittingham from the left by-line, clearance by Marcus Tudgay.
The ref blows the whistle to start the match.
Live text and data provided by The Press Association
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.