Reading 1 Barnsley 2
Barnsley were leading through a 57th minute Daniel Bogdanovich goal when Barnsley defender Rob Kozluk headed an equaliser past his own goalkeeper Luke Steele.
That looked like taking the tie into extra-time, but in the dying seconds there was another twist.
Reading skipper Alex Pearce and Kayode Odejayi tangled and referee Graham Horwood pointed to the penalty spot.
Bogdanovich sent the kick past Reading keeper Ben Hamer and Barnsley were safely through to the next round.
Reading had seen more of the early possession but it was Barnsley who had the better chances.
They had an opportunity to take the lead after just five minutes when a mistake by Julian Kelly allowed John Macken in on goal. The Barnsley striker should have scored but instead blazed high over the bar.
Barnsley striker Odejayi also had two good opportunities but he headed Macken's right-wing cross just wide and then turned past Reading full-back Ryan Bertrand only to see his fierce drive flash over the bar.
Odejayi also turned a Hugo Colace free-kick just wide of the upright.
Reading boss Brendan Rodgers put Republic of Ireland international striker Noel Hunt on as a substitute in an attempt to get a goal back but Hunt was twice denied by superb saves from Barnsley keeper Steele.
The two sides meet again on Saturday in a Championship game at Barnsley.