Both sides were on the brink of dropping into League One throughout the match, but results elsewhere ensured that they remain in England's second tier.
The visitors made the stronger start to the match, but O'Grady could only skew his shot wide from a tight angle in the ninth minute.
It didn't take long for the Tykes to go in front, as in the 16th minute O'Grady made amends for his earlier miss by cutting inside from the left before slotting a curling shot past Alex Smithies into the far corner.
The Terriers came close just before the break when a long kick from Smithies found James Vaughan, but he fired just wide of Luke Steele's goal.
Town again went close to an equaliser moments later, but Oliver Norwood's 20-yard effort flew just past the post.
The hosts had another opportunity just before the break, but Anthony Gerrard's header sailed just wide from Norwood's freekick.
However, Huddersfield drew level just after the break when Danny Ward's pass allowed Beckford to superbly fire past Steele to make it 1-1.
Barnsley nearly went back in front on the hour mark, but Stephen Dawson's chance forced Smithies into making a fantastic save.
However, the Tykes regained their advantage 13 minutes from time when David Perkins ran down the left before crossing to Scotland, who met the ball with a diving header to make it 2-1.
With nine minutes to play, Vaughan found a second leveller for the Terries that ensured that both teams survived.