Macclesfield had eliminated holders Crystal Palace in the last round and more than held their own for long spells at Mose Rose.
Brentford, who sit seventh in the Premier League, made seven changes but were still expected to cruise into round five.
However, the Bees only broke the deadlock 20 minutes from time when PE teacher Sam Heathcote headed into his own net from Aaron Hickey's cross.
Macclesfield, managed by John Rooney, the brother of former England captain Wayne Rooney, pushed for an equaliser in the closing stages but failed to force the tie to extra time.
Brentford's reward for victory is a trip to West Ham in the last 16.
