Goals from Marvin Williams, Charlie MacDonald and Nathan Elder ensured Brentford avoided an FA Cup upset at the home of the Conference South side.
In an end-to-end encounter Craig Watkins saw his goal-bound effort blocked at one end before a Brentford break led to a last-gasp challenge from Gary Elphick denying Bees midfielder Williams.
The opening goal arrived in the 41st minute as Gary Holloway surrendered possession cheaply in midfield and despite home stopper Kevin Scriven denying Elder, Williams was on hand to tuck in the rebound.
Brentford dominated the early stages of the second half and doubled their lead in the 65th minute as Scriven failed to deal with a Glenn Poole corner and MacDonald was on hand to poke the loose ball home.
Back came Havant and Ian Simpemba reduced the arrears in the 73rd minute as he headed home a Brett Poate corner before Elphick was twice denied by Bees keeper Ben Hamer.
But the result was sealed in the 83rd minute as MacDonald raced on to the ball down the right and his cross was turned home by Elder with the Havant defence stretched. The Bees will now face either Eastbourne or Barrow in the second round.