Simon King put the hosts in front inside two minutes but a poor game only sparked into life in the last 15 minutes, when Andy Barcham struck either side of a Gareth Evans penalty.
Gills had only won once in six league games at home, a run which had threatened to undermine their promotion hopes, but it took them less than two minutes to open the scoring.
Macclesfield goalkeeper Jon Brain made an excellent save to tip Dennis Oli's shot round the post but from the resulting corner King headed home Nicky Southall's centre.
For a while it looked like the floodgates might open as Gills swarmed all over a clearly unsettled Macclesfield, but the visitors gradually edged their way into the game.
James Jennings fizzed a 25-yard shot just over the crossbar and then on 30 minutes Matthew Flynn headed over from a corner when he should have scored.
The home side were the better side after the break, but it took them until the 74th minute to extend their lead. Macclesfield, who had defended well up to that point, allowed Mark McCammon the time to sit on the ball, get up and find Barcham, who lashed home from close range.
At 2-0 the game looked over but the Silkmen were handed a lifeline when Barcham was penalised for a handball just inside the box. Evans sent Simon Royce the wrong way to haul the visitors back into the game.
But Barcham had the last word, cutting in from the left flank to curl a great finish past Brain for his ninth goal of the season. It keeps Gills firmly in the race for the play-offs, just a point off League Two's top seven, while Macclesfield remain locked in mid-table no man's land.