Wrexham captain Brian Carey, playing his 300th league game for the club, denied Barnsley a goal in the dying seconds.
Despite playing with an injury he got back just in time to clear off the line from Mick Boulding.
It was an entertaining finish to a game that started as a bore with neither side doing much to impress in the first half.
Chris Armstrong put Wrexham in front right on half time. The ex-Spurs striker nipped into the box after Danny Williams had headed down Andy Holt's long throw and jabbed the ball over the line.
Steve Roberts put the Red Dragons further ahead on the hour forcing a powerful header home from Matt Crowell's corner.
The Tykes fought back and pulled a goal back within two minutes, Daniel Nardiello heading in Chris Shuker's cross.
Having got back into the contest Barnsley went flat out for goals and brought on Barry Conlon, as they decided to play with three men in the front line.
For extra strength they also withdrew Nardiello and sent on Mark Stallard for the last few minutes.
Michael Chopra headed wide for the Tykes earlier on and Andy Dibble made a full-length save to deny Shuker.
Wrexham missed their early chances but Matt Carbon nearly scored with a misplaced header that Nick Colgan managed to save.
Dennis Lawrence headed wide before he was replaced by Shaun Pejic midway through the first half.
Chris Llewellyn aimed a 15-yard shot past the post and Roberts fired wide as Wrexham tried for their first goal.
Another shot from Hector Sam hit a defender and Crowell shot wide from the rebound before a Roberts header was touched over the bar.