Barnsley soaked up early first-half pressure before hitting Gillingham with two sucker punches in quick succession at Priestfield.
Gillingham completely dominated first-half proceedings but paid the price for failing to take any of their opportunities.
Instead Barnsley broke the deadlock against the run of play through Chris Shuker on 40 minutes and two minutes later Paul Hayes doubled their lead in style.
Substitute Danny Nardiello put the result beyond doubt six minutes from time.
Gillingham really should have taken the lead on five minutes through a move which veteran Andy Hessenthaler started but failed to finish. He found Matt Jarvis on the left, his shot was blocked and Hessenthaler, following up with the rebound, could only shoot wide.
Gills looked dangerous again on nine minutes as Jarvis played a neat one-two with Darren Byfield but as his cross rolled across the face of goal no home player was in sight when only the slightest of finishing touches was required.
Barnsley were non-existent as an attacking force until 26 minutes when Shuker had a shot blocked, although they went on to take the lead five minutes before the break.
Gillingham should have gone in front first though as Neil Harris picked out Jarvis with a delightful ball to the left. He turned and his shot forced an outstanding save from Nick Colgan and Harris was just unable to put the ball over the line.
Seconds later Shuker gave his side the lead when he raced towards goal, took it past Danny Jackman and slotted past Jason Brown.
Two minutes later Barnsley were two up as Hayes beat Brown with a majestic chip.
In the second half Gillingham were devoid of ideas as Barnsley shut up shop and Nardiello scored a sublime 85th minute free-kick to seal victory for his side.