Late Wigan goal prevents Gills from returning to the top of the leagueGillingham missed out on the chance of moving back to the top of Sky Bet League 1 after letting a two goal lead slip away to Wigan Athletic.
Dominic Samuel opened the scoring on 24 minutes with his fourth goal in five games, before Rory Donnelly put the visitors two-nil up at the DW Stadium within eight minutes of the restart.
The Latics scored twice in 180 seconds through Will Grigg and Max Power to draw level, before captain Craig Morgan powerfully headed home in the fifth minute of stoppage time.
Manger Justin Edinburgh named the same starting XI for the third-consecutive game, including Samuel, who had extended his loan deal from Reading earlier this week.
And after a quiet opening 13 minutes, a foul on the striker by Wigan defender Leon Barnett presented the Gills with the game's first chance. From the resulting free-kick on the edge of the box, Bradley Dack fired against the top of the post with goalkeeper Jussi Jaaskelainen well beaten.
Michael Jacobs had the hosts' first attempt of the game, shooting straight into Stuart Nelson's hands two minutes later, before Jason Pearce failed to the required contact on David Perkins's dangerous lofted cross into the box that could have given the Latics the lead.
Good play from Josh Wright and Donnelly presented Ryan Jackson with a sight of goal 20 minutes in, but the right back's low, close range effort was deflected away from danger.
And it wasn't long before the Gills' increasing pressure paid off. Aaron Morris gained possession in midfield, Dack's resulting 20-yard through ball found the onrushing Samuel, who outsprinted defender Pearce and coolly slotted past Jaaskelainen.
The hosts initially responded well, creating two good chances in two minutes. First, Jacobs forced Nelson into a good save from his driven shot, and two corners later, the unmarked Andy Kellett somehow headed wide at the back post from six yards.
However, the final 10 minutes of the half were largely played out in midfield, with Jacobs's shot straight at Nelson and Dack's deflected effort from 20 yards the closest either side came to scoring.
The Gills started the second half in similar fashion to the first, coming close to a second on five occasions in the opening seven minutes. Samuel came close barely 90 seconds after the break, volleying over at the near post from a Dack corner.
Link-up play involving Jackson and Dack saw the latter's dangerous cutback knocked wide by Pearce. From the resulting Gills corner, Egan shot into the Latics' defence.
Only a brave clearance from Morgan denied Dack spectacularly volleying into the box from a long Jackson throw, then a heavy touch from the Gills midfielder prevented him from rounding Jaaskelainen and slotting into an empty net having been played through by Samuel.
Given this pressure, it was no surprise when the Gills' lead doubled on 53 minutes. Substitute Doug Loft, who had only come on at the break for Aaron Morris, delivered a pin-point cross to the back post, one which Donnelly headed home.
Egan's block thwarted the progress of Grigg's volley on 63 minutes, Wigan's first attempt in the second half, but the striker made no mistake to bring the Latics back in the game barely a minute later. A lofted ball into the box from substitute Jordy Hiwula was knocked down at the far post by Jacobs, and Grigg duly converted.
And out of nowhere, the game was tied 180 seconds later. Power's seemingly innocuous shot from 25 yards caught out Nelson, who parried into his own net.
Both sides pressed for a winner as the game ended at a frantic pace. Dack shot wide from distance and Samuel's effort gave Jaaskelainen an easy save, while ex-Gills loanee Donnervan Daniels curled inches wide of the post 12 minutes from time.
Egan shot low on 85 minutes after the Wigan defence had failed to clear their lines, only to pick out the alert Jasskelainen.
Daniels again threatened in the fourth of six stoppage time minutes, as his powerful effort was blocked by Bradley Garmston. However, the hosts were not finished there, and in the final minute, Morgan jumped the highest from a Power corner to head home the winner.
The Gills are again on the road next Saturday (January 16th) as they travel to Doncaster Rovers.
Wigan Athletic: Jaaskelainen, Barnett, Morgan, Pearce, Daniels, Power, Perkins, James (Hiwula 55), Kellett (McCann 56) Jacobs, Grigg
Unusued substitutes: Nicholls, Cowie, Davies, Love, Vuckic
Gillingham: Nelson, Jackson, Egan, Ehmer, Garmston, Wright (McGlashan 86), A Morris (Loft 45), Hessenthaler (Osadebe 76), Dack, Donnelly, Samuel
Unused substitutes: G.Morris, Williamson, Norris, List
Attendance: 7, 923
Referee: Mr S Duncan