The visitors would have gone behind but for goalkeeper Adam Davies, who saved to deny Ivan Toney from the penalty spot on 13 minutes, the spot-kick awarded after contact on Joe Ward by Dimitri Cavare.
Toney hit his spot-kick low down to Davies’s left, but Barnsley’s captain was equal to the task.
Posh were punished almost immediately when they failed to clear and the ball came to George Moncur, who scored from close range.
Moncur endured a difficult time during his loan spell with Peterborough two seasons ago and although he had converted a simple, close-range opportunity after Mark O’Hara had been caught flatfooted he celebrated in exuberant style in front of the Posh fans in the main stand.
Brad Potts then rifled in the first of a brace when a 25-yard free-kick was touched to him in first-half stoppage time after Marcus Maddison had dragged down Alex Mowatt when he was threatening to break clear.
Attacking midfielder Potts again found the net just short of the hour mark from 20 yards.
Full-back Darren Lyon had lost possession and Moncur eased the ball on to Potts, who scored his second goal of the game from the edge of the area.
Substitute Jacob Brown scored Barnsley’s fourth goal two minutes into stoppage-time to move the visiting side within two points of their hosts.
Peterborough: Chapman, Naismith, Bennett, Tafazolli, Daniel (Lyon 54), Maddison (Reed 65), Walker (Godden 27), Woodyard, O’Hara, Ward, Toney. Unused substitutes: Dembele, Cooke, Cummings, Tyler.
Barnsley: Davies, Cavare, Pinnock, Lindsay, Ben Williams, Mowatt, Dougall, Potts (Hedges 78), Bahre (Thiam 89), Moncur, Moore (Brown 36). Unused substitutes: McGeehan, Walton, Jackson, Adeboyejo.
Referee: D Drysdale (Lincolnshire).