Defender Matthew Lockwood claimed a remarkable second-half hat-trick to help Leyton Orient secure a draw.
The Gills scored two late first-half goals through Mark Bentley's header and a Guylain Ndumbu-Nsungu tap-in.
Just before the hour Matthew Jarvis fired home for the Gills' third, before Lockwood's penalty made it 3-1.
In the 84th minute Lockwood netted his second with the aid of a deflection and with two minutes left he fired past keeper Scott Flinders for a third time.
Leyton Orient: Garner, Miller, Lockwood, Mackie, Saah, Simpson, McMahon, Chambers, Alexander, Steele (Ibehre 61), Connor (Corden 46).
Subs Not Used: Barnard, Keith, Morris.
Booked: Alexander, Mackie.
Goals: Lockwood 77 pen, 85, 88.
Gillingham: Flinders, Jupp, Jackman, Cox, Johnson, Bentley, Flynn, Crofts, Easton, Jarvis, Ndumbu-Nsungu.
Subs Not Used: McDonald, Clohessy, Collin, Spiller, Pouton.
Booked: Easton, Ndumbu-Nsungu, Flinders.
Goals: Bentley 43, Ndumbu-Nsungu 45, Jarvis 57.
Ref: I Williamson (Berkshire).