Stephen Duke-McKenna's first-half strike was enough to give Harrogate a 1-0 win at Priestfield to end Gillingham's unbeaten start to the League Two season.
The forward evaded challenges on the 18-yard line before firing a left-footed effort into the bottom corner.
The hosts went close through Josh Andrews and Jonny Smith but Harrogate held firm to secure a surprise win.
Following a fairly even start it was Harrogate took the lead just after the quarter-hour mark with their first meaningful chance when Duke-McKenna, on the edge of the box, did well to create space for a shot and fired beyond Glenn Morris.
The advantage should have been doubled shortly after the restart but Ellis Taylor's effort inside the penalty area narrowly went wide of the left post with Morris rooted to the spot.
The hosts came close to an equaliser, but James Belshaw in the Harrogate goal did well to tip Andrews' header away for a corner before palming away a drilled effort from Smith.
Report supplied by PA Media.
Ainsworth: 'You do learn plenty from a defeat'
Weaver: 'Can't have them think we're a small club'