Two second half goals turned the game on its head as Oldham Athletic continued their unbeaten run in Sky Bet League One to four games.
Captain Doug Loft gave the Gills the first half lead with a thunder strike from 30 yards but Latics responded well in the second half.
Tim Dieng’s deft header got Latics back on level terms and with 15 minutes of the game remaining, Jonathan Forte guided home a James Wilson cross to win the game for Athletic.
That victory was the first at home since the 1-0 win over Fleetwood in August and has stretched the club’s unbeaten run to four games.
Manager John Sheridan made two changes to his starting 11 as Anthony Gerrard returned to replace Carl Winchester and Curtis Main got the nod ahead of Rhys Murphy.
Latics started brightly with Aaron Amadi-Holloway striking wide on three minutes but Main won a free kick two minutes later which forced the first real chance of the game.
Danny Lafferty stepped up, got the ball up and over the wall but Stuart Nelson tipped the ball wide of the post.
From the resulting corner, Latics appealed for a penalty as the ball appeared to hit the hand of a Gillingham player but the referee waved away the protests.
Athletic continued their attack on Nelson’s goal and on 10 minutes had another golden opportunity to take the lead.
It was Lafferty this time who turned provider, and he crossed to Main in the centre but he guided the ball inches wide of the post.
Against the run of play, Gillingham took the lead on 16 minutes through a wonder striker from Loft.
After a dangerous corner was half cleared, Loft received the ball 30 yards from goal and rifled it past Joel Coleman, giving him no chance and giving the Gills the lead.
Latics looked to respond straight away and were unlucky not to get an instant reply but Main’s shot from the edge of the box was saved by Nelson’s feet.
Holloway and Main were causing a nuisance in attack, with Holloway battling well with the Gillingham defence.
Just after the half hour mark, the Wycombe loanee had a sight of goal from 25 yards but struck over the crossbar as Latics looked for an equaliser.
Two minutes later, good work from the attacking two saw Holloway feed Jonathan Forte on the left but he side footed over from the edge of the box.
Whilst Latics were creating good chances, they were struggling to get a clear cut chance in front of goal.
It was a slow start to the second half with Gillingham probably shading the early possession.
The game needed a lift and it got that on 56 minutes when Dieng equalised.
After Liam Kelly took a quick free kick, Palmer crossed into the box and it was Dieng’s deft header which got Latics back on level terms.
Sheridan’s men were in the ascendancy and the game started to heat up.
Loft and Rory Donnelly found their way into the referees notebook whilst Matt Palmer was carded for a late challenge.
Whilst Latics were going forward, they had to be wary of the counter attack and they were almost punished on the hour mark.
Bradley Dack broke from the back, played the ball through to Garmston on the right-hand side but Dummigan was back to clear the danger.
Latics were pressuring the Gillingham defence and the comeback was complete on 73 minutes as they went into the lead.
James Wilson, who has been a revelation at full back, delivered an excellent cross into the box and Forte was on hand to notch his second goal of the season to put Latics ahead.
The supporters were really getting behind the players and they went in search of a goal to complete the win.
They almost had it a minute later as Palmer’s cross found the head of Holloway but he just could not direct it on target.
Holloway was replaced to a standing ovation on 80 minutes as Rhys Murphy entered the fray.
It was Latics who almost made it three, had it not been for the referee’s whistle.
Palmer’s corner into the box found the head of the onrushing Anthony Gerrard but the defender was adjudged to have fouled the goalkeeper as he converted.
Main, who had an impressive full debut for Latics, and Murphy both went close in the final minutes but it was nervy in the stands.
With only a minute remaining, Donnelly stooped at the back post but headed over from three yards.
As the fans got edgy, there was a calmness about the players as they kept the ball comfortably in the dying minutes to secure the first win at home since August.
Oldham Athletic: Coleman, J.Wilson, Dieng, Gerrard, Lafferty, Dummigan (Winchester 75’), Kelly, Palmer, Forte, Holloway (Murphy 78’), Main.
Subs not used: Cornell, Mills, Brown, Croft, Cassidy.
Gillingham: Nelson, Garmston, Ehmer, Loft (Hessenthaler 67’), Samuel (Williams 78’), Morris, Osadebe (Norris 78’), Donnelly, Dack, Chickson, Wright.
Subs not used: Morris, Dickenson, Dickinson, List.
Goals: Oldham Athletic (Dieng 56’, Forte 73’) 2-1 Gillingham (Loft 16’)
Attendance: 3,874 (279 visiting supporters)