Barnsley made heavy weather of booking their third round FA Cup spot against second division rivals Bristol City.
Gudjon Thordarson's team had suffered a defeat and a draw against the Robins in recent weeks, but this time it proved to be third time lucky.
They appeared to be cruising at half time, after two set-piece moves had given them a two-goal cushion, but they sat back after the break and almost paid the price.
After a sloppy opening spell, Barnsley gradually got their game going and Kevin Betsy was unfortunate not to score with a feirce low shot that brought a fine fingertip save from Steve Phillips.
Barnsley eventually made the breakthrough on 25 minutes with a straighforward goal.
Brian O'Callaghan floated in a free-kick from the right and midfielder Antony Kay rose unchallenged to head in his second goal in successive games.
Bristol's first effort on goal came in the 33rd minute when Luke Wilkshire latched on to Brian Tinnion's pass, but his shot was blocked by the advancing keeper Sasa Ilic.
And it was Barnsley who went 2-0 up just before the break, Stephen Carson delivering a deep corner and on-loan defender Garry Monk sidefooted in at the far post.
But the Tykes were not at the races in the second half, withdrawing further and further into their shell.
City boss Danny Wilson had thrown on striker Christian Roberts at the break and he reduced the arrears on 66 minutes when he latched on to Wilkshire's throughball and coolly beat Ilic from the edge of the box.
Barnsley then had their backs to the wall, often stringing seven or eight men across their own penalty area, but they somehow hung on, even escaping when City substitute Leroy Lita had a header cleared off the line by Monk.