Captain Montell Moore scored two and made one as Brentford won their FA Youth Cup First Round tie.
The Bees trailed Gillingham, away from home, inside the final quarter of the match but came back strongly.
Moore scored an equaliser and then set up Courtney Senior to put The Bees ahead inside the final ten minutes.
The attacker then scored a third in the dying stages to ensure Brentford progressed.
The Bees deserved it on the balance of play but Gillingham were a decent attacking force and will feel they could have taken the tie.
Only in the later stages, when Gillingham chased the tie, did Brentford look a class above.
The home side probably settled slightly quicker to the environment – knock out cup football, professional ground, floodlights – and had the better of the opening exchanges.
Aiden Blanchard shot wide from 20 yards and Nik Tzanev punched away a dipping, swerving shot from Michael Freiter.
Brentford soon got in to their stride, started to play the football taught all the way from the youngest Academy players to those at Youth Team level, and began to move the hosts around.
When The Bees were able to release the ball quickly and stretch their hosts they looked likely to create chances and the direct running of Kojo Awotwi gave them an outlet.
A low Moore free kick caused chaos and Awotwi had a shot blocked before Bradley Clayton turned away from Josh Staunton and raced clear, his chipped effort, however, was easy for Luke Nalder to gather.
Nalder saved a long range effort from Awotwi before Moore shot just wide.
Brentford were forcing Gillingham in to mistakes, the young Bees pressed high up the pitch and made The Gills go longer.
When the home side got it right and won the aerial challenges they were able to open Brentford up but the visitors had a lot of ball in Gillingham territory.
Awotwi shot over after turning away from the defence and Makhosini Khanye curled a free kick over the top.
At the other end Gillingham’s best outlet was Freiter, who often combined with right winger Mahlon Romeo to good effect.
Tzanev kept out a low Freiter shot before the striker headed over and then forced the Brentford goalkeeper to save to his left.
Danny Leonard also shot over for the home side as they had a good spell.
Brentford almost grabbed the lead before the break when a cross reached Khanye at the far side, he miss-controlled but then blocked a clearance and the ball rolled just wide.
The Bees would have gone in at half time feeling they had the upper hand but with their goalkeeper as the busier of the two.
Gillingham were slightly more effective with their possession and were perhaps on top in the physical battle.
The second half started in similar fashion, Brentford having more of the ball, Gillingham more direct and incisive with their possession.
Nalder saved from Michael Onovwigun before Dan Bent blocked a fierce James Ferry shot and Moore’s follow-up was saved.
Staunton missed a great chance for Gillingham when he headed a Blanchard free kick over from close range but moments later the hosts were ahead.
Brentford should have had a free kick when Clayton’s aerial challenge was met with a high foot but referee David Spain allowed play to go on and the ball was knocked forward, Freiter raced in behind in the inside left channel and lifted the ball over the advancing Tzanev to give Gillingham the lead.
The Bees responded well to going behind and immediately set about levelling it up.
Moore had a shot blocked before substitute Senior cut inside and saw his effort cleared.
Nalder then saved from Senior and Awotwi before Ferry shot over.
The game was beginning to get stretched as Brentford chased it.
Awotwi and Senior were providing pace and width for The Bees but Gillingham were breaking quickly and posing problems when they did so.
Romeo shot over after cutting inside before he was put away by Jack Sellens, Tzanev came rushing out again and the winger lifted his effort wide.
That proved to be a vital moment as Brentford were level within a minute.
Awotwi fed the ball inside; Moore created space and then smashed a shot in to the bottom corner from 20 yards as Nalder was rooted to the spot.
Gillingham refused to lie down and Tzanev had to save from Charlie Webster before Freiter headed wide and then saw a free kick deflect in to the arms of the Brentford goalkeeper.
With Senior and Awotwi on the flanks and Ferry starting to take control of the midfield, Brentford had the upper hand.
They stretched the home defence with balls in behind and looked the more likely winners.
Senior had a shot saved and then one blocked before he appeared to be through in the inside left channel and was pulled down by Staunton, referee Spain saw no offence and waved play on.
Zain Westbrooke shot over after a quick break and soon after The Bees were ahead.
Moore played a delightful ball in behind and Senior broke from the right side in on goal, he slotted calmly under Nalder to put Brentford in front for the first time.
Blanchard shot wide for the hosts and Mitchell Dickenson missed the target with a header but as they poured forward, there was space for Brentford to exploit.
Senior got in behind again on to another Moore pass but this time Nalder saved and Ferry shot just wide after being set up by Westbrooke.
Moore had a shot blocked and then one saved while an Awotwi effort that looked set for the net deflected wide off a defender.
The killer goal came two minutes in to stoppage time – Ferry, by now leaving all in his wake in midfield, strode on to a loose ball and fed Moore, the skipper steadied himself and fired it low in to the corner to seal the win.
Westbrooke shot over at the death for The Bees, who can now look forward to a Second Round tie against Dulwich Hamlet or Brentwood Town.
Gillingham Youth: Luke Nalder; Callum Emptage, Dan Bent (sub Sam Muggleton 70 mins), Josh Staunton, Mitchell Dickenson; Mahlon Romeo, Aiden Blanchard, Danny Leonard (sub Harry Stannard 87 mins), Charlie Webster (sub Ross Ibbertson 72 mins); Jack Sellens, Michael Freiter
Subs (not used); Tom Hadler, Max Kilman
Brentford Youth: Nik Tzanev; Richard Bryan, Gradi Milenge, Seth Owens, Tom Field; Makhosini Khanye (sub Courtney Senior 54 mins), Michael Onovwigun (sub Zain Westbrooke 69 mins), James Ferry, Kojo Awotwi; Montell Moore, Bradley Clayton (sub Lewis Lavender 77 mins)
Subs (not used): Joe Taylor, Josh Stockwell
By Chris Wickham
Click here to read the match as-it-happened.