Jose Veiga twice thwarted Adebayo Akinfenwa early on but Macclesfield took a 17th minute lead when a mix-up in the Cobblers defence saw Marcus Marshall set-up George Donnelly, who finished from close range.
Michael Jacobs put Northampton back on level terms eight minutes later when his deep inswinging corner evaded Veiga and nestled in the far corner.
Donnelly should have restored Macclesfield's advantage in the 33rd minute when he raced clear but was denied by a last-gasp tackle from John Johnson.
Luke Guttridge put Cobblers in front on the stroke of half time, heading home Ben Harding's testing free-kick. Akinfenwa extended Northampton's advantage seven minutes after the restart, controlling Johnson's cross before turning to beat Veiga from 10 yards.
Johnson again came to Northampton's rescue to thwart Donnelly for the second time after he broke into the box. Ben Tomlinson reduced the arrears five minutes from time, finally capitalising on another defensive error, but Cobblers held on to claim three crucial points.