Burton will be promoted to the second tier for the first time if Walsall fail to beat Fleetwood on Monday.
Lucas Akins met Mark Duffy's cross to put Burton ahead with a tap-in finish.
Cody McDonald levelled with a header from a Bradley Dack corner and the Gills piled pressure on Burton before Naylor headed in a Duffy corner.
Gillingham, who are two points adrift of sixth-placed Barnsley after the Tykes drew 2-2 with already-relegated Colchester, suffered an early double blow with Bradley Garmston and Aaron Morris forced off injured inside 16 minutes.
Still, the Gills made it difficult for Nigel Clough's Burton side, with McDonald and Dominic Samuel particularly menacing, but Burton survived a number of scares before Naylor won it.
Tom Naylor's injury-time winner put Burton on the brink of promotion to the Championship and damaged Gillingham's play-off hopes.