Deon Burton climbed off the bench to slot home the penalty which sunk Dagenham and fired Gillingham to the top of npower League Two.
Daggers defender Femi Ilesanmi had levelled things up with a fine finish in the 52nd minute after Leon Legge had put the Gills ahead, but Burton struck to hand his side just a second home win in eight matches.
And with Port Vale slipping up at home to Morecambe, Burton's 11th goal of the season saw Gillingham reclaim top spot.
Legge had the hosts ahead just before the half hour mark in controversial circumstances after referee Iain Williamson awarded a goal despite an offside flag following Myles Weston's deflected free-kick.
But the Daggers were unperturbed as Ilesanmi capitalised on Legge's poor clearance to hammer past Stuart Nelson after the break.
Charlie Lee headed wide from point-blank range for the Gills before Burton struck three minutes after coming on after Daggers keeper Chris Lewington fouled Anton Robinson in the 68th minute.
Luke Williamson headed over as John Still's side sought an equaliser but the Gills held out to return to the top for the first time since January.