Match ends, Cardiff City 3, Barnsley 2.
Cardiff City maintained their unbeaten run under new boss Neil Harris thanks to Lee Tomlin's dramatic late winner.
Tomlin created Danny Ward's equaliser before lashing home the winner in stoppage time.
The bottom side had given an excellent account of themselves in South Wales and twice led through Conor Chaplin's opener and a Lee Peltier own goal.
However, Bambo Diaby's deflected own goal, Ward's fine finish and Tomlin's dramatic winner earned Cardiff victory.
The win means Cardiff rise to eighth, while Barnsley remain bottom of the Championship.
You certainly would not have known what a perilous position the Tykes are in based on a fine first half display where they created more chances than the hosts.
Compact, organised and brave in possession, Barnsley looked anything but a side struggling at the foot of the table.
They had already threatened through the lively Chaplin whose fierce drive was blocked when they took the lead on 16 minutes as Cardiff turned over possession and Chaplin stroked home after Mike Steven-Bahre slipped him in.
The goal came just a minute after Junior Hoilett's curling effort from 25 yards had just skimmed the Barnsley goal.
However, Barnsley held their lead for only four minutes before Hoilett's pinpoint cross was turned home at the near post via a combination of Aden Flint, who got across his marker, and Barnsley defender Diaby.
The Bluebirds sensed a chance to take control but, after Gary Madine's effort was ruled out for a contentious offside, Barnsley began to break at pace and came close when Neil Etheridge fumbled Bahre's stinging effort. Chaplin also could have added a second, but he fired over at the near post.
However, Barnsley kept their momentum after the break and led within two minutes when Diaby avenged his own goal by beating Lee Peltier to the ball to turn home. Again it was questionable who got the decisive touch, although Diaby certainly celebrated like he did.
The goal was no less than Barnsley deserved and for 10 minutes they dominated, but crucially did not find a third goal to ensure a nervous finish.
Cardiff were creating very little but from nothing they grabbed an equaliser when Lee Tomlin's skill and vision provided an opening for substitute Danny Ward who fired into the roof of the net to set the stage for a grandstand finish.
Marlon Pack volleyed over and Tomlin dragged wide as the hosts pushed for a winner, which eventually came deep into added time when Tomlin crashed the ball home at the back post as Barnsley failed to clear.
The loss means the Tykes have gone 17 Championship games without an away win.
Cardiff City manager Neil Harris told BBC Sport Wales:
"First and foremost let me be very honest, that wasn't a great performance from us.
"I thought we were a little bit lethargic and I'll hold my hands up for it. We've had a tough week, when we don't have a midweek game I have to find a way of working the group and getting them up to speed because maybe I pushed them too hard.
"We saw a performance where we were half a yard off it. Credit goes to Barnsley, I spoke before about their qualities and how hard they work and they made it difficult for us, but we weren't great.
"But I will praise my players by saying they found a way to win, and good sides find ways to win. "We've got 10 points from four games, so my players are finding ways to win."
Barnsley manager Gerhard Struber told BBC Sport Wales:
"The feeling now is like being hit in the head. I am very frustrated and disappointed for me, my staff and my team.
"We had control of the game in the first 20 minutes of the second-half, we had the lead, but after the equaliser I saw the mentality of the previous month in my players.
"The mindset was not to go on and win the game, the personality is not to go and get the next goal, many players were thinking it would be difficult.
"This change is my job and responsibility, I need to change the mindset so the players believe they can win, but now it's only a mentality situation. The history of losing is in their minds.
"I think when the performance is good and you have this result, it is more frustrating."
- 7BacunaSubstituted forVaulksat 75'minutes
- 17TomlinBooked at 80mins
- 33HoilettSubstituted forMurphyat 59'minutes
- 24MadineSubstituted forWardat 65'minutes
- 6AndersenBooked at 80mins
- 3WilliamsBooked at 90mins
- 24HalmeBooked at 40mins
- 10BähreBooked at 62minsSubstituted forOduorat 90+3'minutes
- 27MowattBooked at 90mins
- 7BrownSubstituted forSchmidtat 82'minutes
- Paul Tierney
- Shots on Target
Second Half ends, Cardiff City 3, Barnsley 2.
Attempt blocked. Clarke Oduor (Barnsley) left footed shot from outside the box is blocked. Assisted by Alex Mowatt.
Alex Mowatt (Barnsley) is shown the yellow card.
Goal! Cardiff City 3, Barnsley 2. Lee Tomlin (Cardiff City) right footed shot from the centre of the box to the bottom left corner. Assisted by Aden Flint with a headed pass.
Foul by Aapo Halme (Barnsley).
Curtis Nelson (Cardiff City) wins a free kick in the defensive half.
Substitution, Barnsley. Clarke Oduor replaces Mike-Steven Bähre.
Conor Chaplin (Barnsley) wins a free kick in the defensive half.
Foul by Will Vaulks (Cardiff City).
Attempt missed. Marlon Pack (Cardiff City) right footed shot from the centre of the box misses to the right.
Corner, Cardiff City. Conceded by Aapo Halme.
Ben Williams (Barnsley) is shown the yellow card for a bad foul.
Foul by Ben Williams (Barnsley).
Josh Murphy (Cardiff City) wins a free kick on the right wing.
Attempt missed. Lee Tomlin (Cardiff City) right footed shot from outside the box is close, but misses to the left. Assisted by Aden Flint with a headed pass.
Foul by Patrick Schmidt (Barnsley).
Aden Flint (Cardiff City) wins a free kick in the defensive half.
Attempt missed. Marlon Pack (Cardiff City) left footed shot from the centre of the box is just a bit too high following a corner.
Corner, Cardiff City. Conceded by Bambo Diaby.