Charlie Adam claimed his seventh goal of the season with a 78th-minute penalty to put the Seasiders on course for victory.
The highly-rated midfielder held his nerve to fire home from 12 yards after Ryan Shotton had handled in the box but the Tykes fashioned a late rally that reaped rich rewards.
However, Barnsley were not to be denied and they were level when Hassell nodded in Iain Hume’s corner with five minutes remaining.
They snatched the points in the 88th minute when Baptiste was punished for a handball offence and Gray kept his cool to fire into the top corner from the penalty spot.
The defeat sees the Seasiders drop to eighth in the table while Barnsley remain 15th.