Colin Daniel struck twice to leave Gillingham's play-off hopes hanging by a thread as mid-table Macclesfield upset the odds.
Ross Draper gave the Silkmen a shock lead before Daniel's first-half double left the Gills stunned. Danny Jackman snatched a goal back but Emile Sinclair hit the fourth before Joe Martin added a consolation.
With Macclesfield's first attack, Draper latched onto a loose ball and drilled past Alan Julian on three minutes. And four minutes later, Sinclair ripped open Gills defence and pulled back for Daniel to slam in the visitors' second.
Still rocking from the early assault, Andy Hessenthaler's play-off chasers slipped three behind on 17 minutes after Daniel weaved through the Gills' defence.
Cody McDonald spurned a chance to pull one back before Jackman volleyed in Martin's 43rd minute cross from close range, but the Gills' hope was soon turned into misery when Sinclair took advantage of sloppy defending on 48 minutes.
Martin scrambled the hosts' second on 71 minutes but their play-off fate now depends on results going their way on the final day.M