Neil Danns claimed a 12th-minute opener before Harry Bunn doubled Bury’s lead in the 25th minute.
Connor Ogilvie pulled one back for mid-table Gillingham after 69 minutes but the Shakers hung on to move within eight points of safety.
Bury impressed in the first half, with Bunn hitting a long-range effort straight at Tomas Holy before Zeli Ismail fired wide.
Ismail then found Danns on the edge of the box and his low shot crept under Holy.
The hosts remained on top, with Bunn dragging a shot wide before sweeping in Ismail’s cut-back.
Lee Martin replied by firing wide, but Bury forward George Miller forced a save from Holy.
Holy denied Miller again just after the break, with Bunn’s follow-up blocked on the line.
And the Gills rallied with substitute Scott Wagstaff blazing over before crossing for left-back Ogilvie to head home.
Wagstaff then curled a shot wide in stoppage time and goalkeeper Holy had a shot saved after going up for a corner, but the Gills could not avoid just their second defeat in 14 league games.
Preston are reportedly weighing up whether or not to make a fourth offer for Peterborough United left-back Andrew Hughes.
James Maddison has completed his move from Norwich City to Leicester City for an undisclosed fee.