Despite an early red card for Matty Pearson, Barnsley took a 38th-minute lead with 10 men as Romal Palmer found the net with a low free-kick.
The home side went close to a second goal despite their numerical disadvantage, but Pompey substitute Bradley Lethbridge inspired a turnaround.
On 88 minutes he crossed for Dan Smith to equalise before Lethbridge added a stoppage-time goal to his assist, earning a dramatic victory.
The win moves Portsmouth up to four points, one point above third-placed Everton having played two more matches. Barnsley are bottom on goal difference.
Barnsley: 12 Feb v Everton (H) PL Cup
Portsmouth: 23 Jan v Everton (A) PL Cup