Mustapha Carayol and Cameron Park grabbed a goal each as Middlesbrough made it through to the third round of the Capital One Cup with a 2-0 victory which ended Gillingham's winning run in the process.
Carayol blasted the visitors ahead in the 23rd minute, bursting through the middle and smashing past Stuart Nelson in the Gills goal.
Scotland Under-21 international Park secured victory in the final minute, chipping over Nelson following Danny Kedwell's poor pass.
Swansea target Marvin Emnes almost had Middlesbrough ahead in the opening five minutes when he beat the offside trap only for Nelson to deny him.
Kedwell then fired wide but Boro went straight down the other end and Carayol bundled his way through before beating Nelson for the opener.
The Gambian winger almost doubled his tally straight after the break only to see his effort deflect off Callum Davies and onto a post.
Gillingham should have equalised when Deon Burton headed on for Kedwell but the striker fired just wide before Boro saw highly-rated defender Rhys Williams stretchered off after twisting his ankle.
The hosts dominated the closing stages but when Kedwell lost the ball in midfield Park broke clear and chipped Nelson to seal the win after 89 minutes.