Gillingham have been knocked out of the FA Cup's first round for a second year in a row, with Bristol City advancing through to the next round.
Goals in either half for City proved to be enough, despite a late fightback from League One's relegation strugglers.
Greg Cunningham broke the deadlock five minutes before the break, while Jay Emmanuel-Thomas doubled his side's lead with 15 minutes left.
Gillingham gave themselves the chance to get back into the game as Danny Kedwell's successful penalty brought City's goal advantage back down to just one.
The League One leaders held out for the last 10 minutes to advance through to the next round of the FA Cup.