An error from Gillingham centre-back Brent Sancho helped Millwall on their way to a first round Carling Cup win. Sancho's slip allowed Millwall striker Kevin Braniff to steal in and drill a shot past Darren Randolph.
On 81 minutes substitute Andrew Crofts connected with a Clint Easton corner to head Gillingham level.
But with five minutes remaining Filipe Morais flighted in an enticing corner and forward Poul Hubertz climbed to angle his header beyond Randolph.
Millwall: Pidgeley, Ross, Robinson, Whitbread, Bakayogo (Craig 78), Hackett, Elliott, Ardley (Morais 45), Mawene (Hubertz 66), Brighton, Braniff.
Subs Not Used: Day, Fuseini.
Booked: Robinson, Braniff.
Goals: Braniff 39, Hubertz 85.
Gillingham: Randolph, Jupp, Sancho, Cox, Jackman, Jarvis, Bentley (Crofts 60), Flynn, Easton, McDonald (Mulligan 73), Ndumbu-Nsungu.
Subs Not Used: Johnson, Pouton, Clohessy.
Booked: Jupp.
Goals: Crofts 81.
Att: 5,040
Ref: K Stroud (Dorset).