Gillingham's play-off hopes suffered a huge blow as two Colin Daniel goals helped Macclesfield secure victory.
Ross Draper drilled the visitors ahead, before good work from Emile Sinclair allowed Daniel to double the lead.
Daniel made it 3-0 after a fine run, but Danny Jackman volleyed in a Joe Martin cross to give the Gills hope.
Sinclair struck just after half-time to restore Macclesfield's three goal-advantage, before Martin scrambled in a late consolation.
Gillingham remain outside the play-offs - level on points with seventh-placed Stevenage - but needing to make up a goal difference of five in the final fixture of the season.