Craig Reid's 11th goal of the season just after the break put the Shots on course for a second straight home win under new boss Andy Scott but Legge popped up to equalise with 15 minutes remaining.
Adam Barrett glanced a header wide before Deon Burton only found the side-netting in the early moments as Martin Allen's side flexed their muscles.
At the other end, Reid's flicked header looked destined to put the Shots ahead but Legge made a desperate clearance while goalkeeper Stuart Nelson flapped at Danny Rose's stinging drive as the relegation strugglers came back into the game.
And their renewed fight was rewarded two minutes after the break as Reid smashed a half-volley into the roof of the net on the turn.
The Gills offered little in reply but levelled with quarter of an hour remaining as Legge galloped forward and headed home Chris Whelpdale's deep cross.
Danny Kedwell should have provided the winner for Gillingham a minute later but Jamie Young somehow saved his point-blank header.