Gillingham’s interest in the FA Cup ended at the first hurdle on Saturday.
Visitors Bristol City took the lead late in the first half through Greg Cunningham.
Jay Emmanuel-Thomas netted a second for City but a Danny Kedwell penalty for Gills ensured a frantic end at Priestfield.
The Gills were unable to score a second, despite pressing in the dying minutes, as City hung on for a place in round two.
League 1 leaders Bristol City, with only one defeat all season, offered a major challenge to the Gills.
Boss Peter Taylor had asked for more time to get things right at the club, during his midweek press interviews, having won just one of their previous 12.
His team needed a boost from somewhere.
And the Gills made a positive start to Saturday’s game, infront of a season-low crowd of 2,654.
Leon Legge forced a save from the visiting keeper early on with a header and fellow central defender John Egan put a chance just wide.
By the midway point of the half Bristol City had begun to assert their authority.
A sliding last-ditch tackle from Egan denied Luke Ayling while Kieran Agard lashed a shot in Nelson’s arms with a shot on the turn.
Legge came close to putting the ball into his own net, with a sliced clearance, moments before City went ahead. A cross from Scott Wagstaff was met at the far post by Cunningham, who turned the ball home from close-range.
Former Gills youngster Luke Freeman drew a save from Nelson before the break.
Taylor made a switch at the break, reverting to a 4-4-2 formation, as he removed a defender for winger Jermaine McGlashan.
Cunningham should have doubled City’s advantage early in the second half, from a Freeman cross, but from just a few yards out he smashed the ball over.
Cody McDonald stabbed an effort wide for the Gills, shortly before being replaced, in what was a rare shot at goal for the hosts.
Bristol City scored a second on 77 minutes when Emmanuel-Thomas side-footed home from 25 yards.
The Gills were down but not out and four minutes later referee Patrick Miller pointed to the spot after Aden Flint handled on the box. Kedwell smashed the ball home to halve the deficit.
Taylor's men gave their all for an equaliser at the end but City's rearguard stood firm.
Gillingham: Nelson, Martin, Egan, Hause, Legge (McGlashan 46mins), Hoyte (Dickenson 75mins), Loft, Hessenthaler, Doughty, Kedwell, McDonald (German 67mins). Subs not used: G Morris, Fish, Pritchard, Dack.
Bristol City: Fielding, Wagstaff (Burns 74mins), Cunningham, Ayling, El-Abd, Flint, Pack, Elliott, Freeman, Agard (Bryan 90mins), Emmanuel-Thomas (Wilbraham 86mins). Subs not used: Richards, Williams, Osborne, Smith.
Attendance: 2,654 (254 away)