It had earlier seemed that Gravesend and Northfleet were heading for a shock victory when they went ahead in the 2nd minute through a goal-mouth melee from a corner which ended with Nathan Clarke heading into his own net with Margetson nowhere.
They might have had a second in the 21st minute when Francis Duku headed home but the goal was disallowed for what appeared to be a push on Kevin Gray.
The Terriers were poor in the first half with only Danny Schofield's 39th minute bar rattler to show for their efforts against a Fleet side whose exertions meant that they were tiring at the end of the first half.
Town were booed off at half time but hardly improved in the second half, despite a probable roasting in the dressing room at half time, where they played just as poorly as they did in the first.
Long balls pumped up to Booth and Knight were getting sent back by the tall visitors who were keen to challenge for everything despite looking increasingly tired as the second half played out.
The Fleet were helped by some outstanding saves by Jamie Turner, who went on to deny Andy Booth, Kevin Gray and Chris Holland in the course of the second half.
Just as things started to get gloomy for Town, Adie Moses popped up with an 63rd minute equaliser.
Kenny Irons had just started to string some passes together in the midfield and he found Moses with one of these passes. Moses cut inside and drilled a left foot effort beyond the otherwise outstanding Jamie Turner.
The prospect of a replay, rather than a defeat, spurred the Terriers on and, helped by a quickly tiring Fleet side, Lou Macari brought on Simon Baldry and switched formations in order to attack their visitors.
Dwayne Mattis went close as both sides attacked but, despite an 84th minute glimmer for Fleet when Matt Lee punted a rebound over the bar from 10 yards out, neither side could find the breakthrough.
With the game heading towards a lengthy injury time and probable replay in Kent, Leon Knight popped up to slot home the winner. It came from a Simon Baldry cross which eventually fell to the Chelsea youngster who put the ball past Turner to seal a deserved victory.
Read Mel Booth's match report on Monday. Let us know your comments via the form on the right of this page or in the comments form below.
Town (4-4-2): Margetson, Heary (Baldry 74), Gray, Clarke, Moses, Irons, Holland, Booth, Knight, Mattis, Schofield
Subs not used: P. Senior, Dyson, Macari, Hay
Booked: Moses, Knight
Scorers: Moses 63, Knight 90
Gravesend and Northfleet (4-4-2): Turner, Lee, Martin, Lye (McKimm 85), Barnett, Duku, Smith, Owen, Wilkins (Hatch 74), Stadhart (Booth 65), Jackson
Subs not used: Skinner, Blake
Booked: Lee, Smith, Wilkins
Scorer: Clarke (og) 2
Referee: Mark Cowburn
Attendance: 6112 (591 Away Fans)
See subsequent pages for match points.
97 mins: Margetson made the save as the referee blew the final whistle.
96 mins: Clarke conceded another corner as the game strayed into a nail-biting finish.
96 mins: A last gasp corner for Fleet saw Jamie Turner go up field but Andy Booth made a clearance.
95 mins: Both sides tussled in midfield as time ran out.
94 mins: Andy Booth was fouled by the 'keeper in his area but the referee ignored appeals for the penalty.
90 mins: Danny Schofield should have scored but Turner was still alert and made the save as Fleet tried to force the replay in the 5 minutes of added time.
90 mins: Leon Knight finally slotted home late on to guarantee a place in the second round. It was a great move involving Simon Baldry and Kenny Irons. A great Baldry cross found Andy Booth who knocked it down for the Chelsea loan man who did the rest.
89 mins: 5 minutes of added time were indicated.
88 mins: Leon Knight's left footed turn and drive was inches wide after he finally got a good pass.
87 mins: Andy Booth was denied by Barnett as Town pushed for the winner.
84 mins: Matt Lee put over the Town bar from 10 yards after Nathan Clarke had slid in to clear a Fleet cross.
83 mins: Andy Booth's downward header went straight into Turner's hands.
82 mins: Liam Hatch won the ball in midfield as Fleet continued to hold their own against the Terriers despite most of them visibly tired.
81 mins: Leon Knight was still a danger as Town went for the win.
79 mins: Paul Booth combined with Jimmy Jackson to shoot on target but Margetson made the save.
76 mins: Mattis' 25 yarder took a touch off a defender and went for a corner after Kenny Irons' free kick had been flicked down by Andy Booth.
75 mins: Baldry tried to turn his defender but he lost the ball.
74 mins: Knight tried to nip in to take the loose ball but he was brought down by a dreadful tackle with an arm which floored him. The referee didn't see fit to punish anyone. Simon Baldry replaced Thomas Heary as Lou Macari gambled on a 3-5-2 formation to win the game.
73 mins: Darren Smith found Matt Lee whose cross was headed into the arms of Margetson by Craig Wilkins.
72 mins: Town were trying to kill off the visitors quickly with more attacks towards the end of the game.
70 mins: Andy Booth tried to get behind the Fleet defenders but couldn't find a way through.
66 mins: Paul Booth replaced Stadhart as Gravesend looked to hold on to the draw to take Town down to Kent.
65 mins: Fleet won a corner but Town cleared this time as their visitors looked tired.
63 mins: Adrian Moses scored the equaliser for Town after cutting inside and unleashing a left foot effort! Kenny Irons was getting his passing game together again and it was he who provided the final pass amongst some tired Fleet defenders.
61 mins: A long throw by Nathan Clarke was headed away by Duku as Town started to lay seige to the Fleet goal.
56 mins: Chris Holland skied a half chance.
55 mins: Irons conceded a free kick as Town struggled to keep Gravesend at bay.
53 mins: Booth was tackled by Robert Owen as Fleet remained tenacious.
52 mins: Owen nipped round Holland but his poor ball was cut out by Moses who subsequently wasted his chance to start a Town attack.
51 mins: A poor free kick by Kenny Irons was countered immediately by Owen who attacked with Smith before Gray and Booth completed the clearance.
50 mins: Thomas Heary completely mislaid a pass for Holland which went out for a throw in.
49 mins: Town were predictable as both sides struggled for the upper hand in the second half.
47 mins: Knight was booked for dissent after a clash with Francis Duku.
46 mins: Thomas Heary had to be alert to cut out an attack by Fleet.
Town have 45 minutes to rescue themselves after a stunning start for Gravesend and Northfleet at the McAlpine.
A goalmouth melee from a corner saw Nathan Clarke's header fall into his own goal in the 2nd minute with Martyn Margetson poised to make the save behind him.
Francis Duku headed a second goal after 21 minutes which was disallowed but Town were under the cosh for much of the opening period of the game.
It was only towards the end of the half, with their part-time visitors flagging after their early efforts, that Town started to get back into the game.
Leon Knight, with his pace, and Danny Schofield, with a curling 39th minute effort which struck the bar, were Town's only threats.
Lou Macari surely has a major team-talk ahead of him...
51 mins: Mattis robbed a Fleet player and tried to pass long for Andy Booth but Duku was faster than Booth and cleared.
50 mins: Barnett cleared from Andy Booth after Knight's shot came off Turner and went towards the big Town striker.
49 mins: Stadhart picked up a poor backpass - his chance was eventually stabbed clear but not before Fleet got a good move together.
48 mins: Knight picked up a deep ball and put a long ball over the top.
46 mins: Aaron Barnett went down in an aerial challenge with Andy Booth as Town plotted a late first half goal with their visitors starting to tire after an energetic first half.
44 mins: 5 minutes of added time were indicated as Town laboured on in the first half.
43 mins: Town were beginning to gain control of the match with their superior fitness levels emerging.
40 mins: Leon Knight was foiled again by Turner when it looked like he was in a good position to shoot.
39 mins: Danny Schofield's turn and curled shot caught the 'keeper off his line but he struck the bar.
36 mins: Andy Booth's effort was wide after a great delivery from Kenny Irons. There was little service for the strikers in this game.
35 mins: Town fans were becoming vocal in their displeasure despite the fact that the visitors were making enough mistakes for Town to capitalise on.
32 mins: Stadhart was closed down by Gray as Fleet tried to break free. Heary invited jeers from the home crowd as an aimless long ball fell into Fleet possession.
25 mins: Gravesend got behind the ball again as Town tried to break through for the equaliser. Andy Booth was being triple marked at times.
22 mins: Andy Booth's flicked header was sent goalwards by Leon Knight but Jamie Turner was, once again, in a good place to make an easy save.
21 mins: Francis Duku headed the ball into the back of the net from a corner but it was disallowed for an infringement against Kevin Gray. Town were again in disarray.
18 mins: The Fleet were sitting deep and hitting long balls, which allowed Town to attack.
16 mins: Knight ran at the Northfleet defenders but Turner was out of his goal quickly to clear the ball.
15 mins: Irons tried a 30 yarder but it was blocked by a defender.
13 mins: A long ball for Leon Knight was cleared by Turner but only as far as Schofield who could only fire wide from 35 yards with Turner scampering back to his line.
9 mins: Knight got a shot on target but Jamie Turner was equal to it.
8 mins: Schofield was beaten by Smith who fed Jackson for a Fleet attack.
7 mins: Town finally got a move together but Holland was crowded out by a Fleet of defenders.
6 mins: Town were playing very poorly as the Fleet pushed on bravely, looking to add to their surprise starting goal.
4 mins: The McAlpine was stunned as Town tried to regroup and start again.
2 mins: There was a goalmouth melee from the second corner and Nathan Clarke rose to head the ball but it fell into his own goal! The linesman flagged for an infringement but the referee was adamant that the goal stood after the ball had flown into a packed Town box.
2 mins: Gray scrambled the corner away but conceded another corner in the process.
1 min: Smith's cross was put out for a corner by Thomas Heary. Town were defending deep again.
In a late development, Leon Knight was cleared to play in Town's FA Cup 1st Round Tie against Gravesend and Northfleet.
Knight was joined in the starting lineup for Town by Andy Booth and Adrian Moses - the latter replacing Steve Jenkins who had sustained a calf injury in training.
Simon Baldry started on the bench for this match.