Samuel gave the hosts the lead when he latched onto Rory Donnelly's through-ball to finish past keeper Adam Davies.
Conor Hourihane levelled for Barnsley on the volley but, a minute later, Davies parried Donnelly's shot into the path of Dack who tapped home.
Hourihane could have levelled again but his late long-range shot went wide.
Gillingham moved up to second in the League One table with victory over Barnsley thanks to goals from Dominic Samuel and Bradley Dack.