Bristol City striker Nicky Maynard scored an injury-time winner to sink Barnsley and give Derek McInnes his first win as Robins manager.
City took the lead when Maynard put Albert Adomah through on goal with a good pass and the winger slid the ball under Tykes keeper Luke Steele.
Craig Davies levelled the scores from 12 yards out, converting Jay McEveley's cross for his first Barnsley goal.
But Maynard had the last say when he smashed home from the edge of the area.
The game was McInnes' second in charge at Ashton Gate following his move from St Johnstone, with the first a 2-0 defeat by Birmingham on Sunday.
The win was only City's second of the season and their first since August.
However, until Maynard's late winner from Adomah's cross, Barnsley had looked the more likely team to win following Davies' equaliser.
City goalkeeper David James pulled off a fantastic save to deny Davies and Stephen Foster headed just wide from the resulting corner.
Summer signing Davies was again frustrated by former England international James before Maynard struck for his fourth goal of the season and his first in his last 11 games.