Andrew Surman dived full length to head Bournemouth an injury time winner and leave Gillingham still looking for their first away win of the season.
The match was deep into the three minutes being added on for injuries and stoppages when Surman met a low centre from James Hayter to give goalkeeper Jason Brown no chance of saving.
Surman, on loan from Southampton, was booked for over-celebrating his sixth goal of the season.
Gillingham had every reason to feel aggrieved after missing a host of first half chances and going ahead through Neil Harris in the 62nd minute.
Matt Jarvis should have done better with a seventh minute chance after being played clear by Danny Spiller and Danny Jackman went close with a fierce low shot after 21.
Gareth Stewart made a great diving save to push away a shot from Harris and Bournemouth were lucky to survive until Harris's goal.
Jarvis dispossessed Callum Hart on the touchline before getting in a low centre which Harris diverted past Stewart from 10 yards.
Bournemouth had not managed a shot on target until their equaliser four minutes later.
Young defender John Wallis failed to clear and Hayter punished him by running clear to beat Brown with a low left-foot shot for his 11th of the season.
Steve Fletcher stabbed wide from 10 yards as Bournemouth got on top, but many fans had already drifted home by the time Surman headed in his winner to keep Bournemouth among the play-off contenders.
Gillingham had plenty of opportunities to have at least gone away with a draw but Harris headed over the bar from six yards and Tom Williams had a shot held by the goalkeeper.
Gillingham had Wallis and Ian Cox booked for fouls while Bournemouth's James O'Connor joined Surman in receiving a yellow card for throwing the ball away after a free-kick had been awarded against him.