Oldham Athletic 2 Gillingham 0
The Gills have not won on their travels since March and they fell victim to Oldham super sub Luke Beckett who scored twice in the last six minutes.
There were few chances in a game of poor quality but Beckett's finishing lit up Boundary Park as he converted two headers.
They earned Oldham their first victory in four matches and kept the Latics in the chase for a League one play-off spot.
Oldham striker Chris Killen, who declared himself fit despite having nine stitches in a head wound sustained at Nottingham Forest last week, wasted the best opening of the first half.
Killen blazed over with just the keeper to beat after being fed by a good low cross by Andy Liddell. Paul Warne also fired off target while Gillingham's Neil Harris hit a quick free-kick which had Oldham keeper Chris Day scrambling along his line.
But Gillingham were without key strikers including the suspended Darren Byfield and they struggled to cause any sort of threat going forward.
Chris Swailes headed wide for Oldham and midfielder Anthony Grant, making his home debut on loan from Chelsea, failed to convert a Mark Hughes cross.
Gillingham's attacks usually ended with long-range shots but they were not good enough to test Day. Oldham broke through on 84 minutes when Liddell knocked back a cross and Beckett found space to beat Jason Brown from close range.
It took only three minutes for Oldham to confirm their victory when David Eyres crossed from the left and the unmarked Beckett steered his header inside Jason Brown's left-hand post from ten yards.