Goals from Adrian Cieslewicz and Neil Ashton gave Wrexham a healthy lead to take into the second leg of their FA Trophy semi-final with Gainsborough.
Blue Square Bet Premier side Wrexham gained an early advantage over their lower league opponents with Danny Wright's composed finish.
Darryn Stamp soon equalised with a powerful header before substitute Cieslewicz restored the home lead.
And in added time, Ashton's acrobatic finish put Wrexham in firm command.
Conceding the third was slightly unfair on part-timers Gainsborough, and gives a totally difference complexion on the tie as Wrexham seek a first Wembley appearance in their history.
Cieslewicz's second-half introduction proved the turning point as the winger gave the home side the pace and penetration that had been missing from their slightly laborious passing play.
Gainsborough, fifth in the Blue Square Bet North and conquerors of Conference Premier sides Forest Green, Barrow and Tamworth on their way to the semi-finals, looked capable on the break and dangerous from set-pieces to suggest they could still spring an upset.
They responded well to the early set-back at the Racecourse as Wright settled any potential anxiety among the home players with the opening goal.
Brett Ormerod's low drive from the edge of the area was palmed away by Gainsborough goalkeeper Jan Budtz, and Wright followed up before the static defenders to stroke the ball into the bottom corner.
Wrexham could easily have scored three more in seven minutes after Wright's opener.
First, the striker had a backward header cleared off the line; Rob Ogleby wasted a one on one with goalkeeper Jan Budtz by dragging his shot wide before Wright wasted the best chance by firing wildly over the bar after the ball sat up perfectly for him on the half-volley near the penalty spot.
The visitors made Wrexham pay for their profligacy as Stamp, an aerial threat throughout, equalised within eight minutes of Wright's opener.
Jamie Yates was given too much time to deliver a cross to the far post, where former Chester City striker Stamp rose dominantly above Martin Riley to head the ball into from the direct it came and into the bottom corner.
Riley was then forced to clear off his own goal-line as Wrexham goalkeeper Chris Maxwell made a meal of trying to gather a floated corner.
Wrexham showed their attacking intent straight from the restart as a flowing move ended with Wright's shot wrong-footed Budtz but just past the post.
More intricate passing, with Wright and Ormerod prominent, ended with Harris firing over, but Cieslewicz showed better composure to restore the home advantage on 65 minutes.
The winger had been on the pitch for only a few minutes when he pounced on a mistake by left-back Danny Hone to race clear and fire past Budtz.
Wrexham pressed for the third to give them some breathing space before the second leg. Cieslewicz headed over and then sent a toe-poke wide; Harris saw a shot cleared off the line and player-manager Andy Morrell found the side-netting.
But the goal arrived in the third minute of added time from an unlikely source as left-back Ashton scored with high left-foot volley after Morrell's initial effort from a corner was saved by Budtz.
Views from the dressing room
Wrexham-player manager Andy Morrell told BBC Radio Wales:
"It could have been more looking at the chances we've had.
"But we knew what they were about - they were going to fight. It was a big game for them, and for us, with the carrot that's dangled in front of you.
"We knew they would tire because part-timers do in big games. Second-half we were good and on the front foot and were worthy winners and it should have been more really."
Gainsborough manager Steve Housham said:
"The tie is certainly not over, anything can happen at our place.
"I'm proud of the lads but mistakes have cost us a few goals. We worked hard but looked nervous, particularly in the first 20 minutes.
"It's all to play for, we're not out of this and we'll give it our best shot in the second leg."
Chris Maxwell, Declan Walker, Chris Westwood, Martin Riley, Neil Ashton, Jay Harris, Dean Keates, Joe Clarke, Danny Wright, Brett Ormerod Rob Ogleby.
Andy Coughlin, Glen Little, Johnny Hunt, Adrian Cieslewicz, Andy Morrell.
Jan Budtz, Dominic Roma, Danny Hone, Luke Waterfall, Josh Wilde, Simon Russell, Craig Nelthorpe, Terry Hawkridge, Michael Leary, Jamie Yates; Darryn Stamp.
Jason White, Greg Young, Shane Clarke, Tyrone Thompson, Bradley Barraclough.
Andrew Madley (West Yorks).