The 30-year-old, on loan from Leicester, slotted home the only goal of the game in the 16th minute, after North End midfielder John Welsh drew a foul in the box, as Preston kept pace with the League One leaders.
Gallagher’s spot-kick was the first real chance of the game while Barnsley’s best effort came right after the restart.
Dale Jennings broke away down the left and into the area but he could only fire a tame shot at Thorsten Stuckmann in the Preston goal.
The chances kept coming for Preston and Scott Laird really should have put the game to bed with a point-blank header. However, he directed his effort straight at Barnsley goalkeeper Adam Davies.
And, despite Conor Hourihane rattling a post in injury time for the visitors, Preston held on for a valuable win which keeps them as one of three clubs on 44 points – a single point behind leaders Bristol City.