Elliott List smashed home a late winner as League One strugglers Gillingham produced an FA Cup third round shock by dumping out Cardiff with a 1-0 win.
Midfielder List buried his finish past Bluebirds goalkeeper Alex Smithies with nine minutes remaining at Priestfield to upset the Premier League visitors.
Cardiff had been the better side in Kent but were unable to make a breakthrough as they twice hit the woodwork in the second period and squandered numerous other chances.
Nathaniel Mendez-Laing went closest for the visitors when he curled against the crossbar 20 minutes from time, while Gills defender Gabriel Zakuani earlier diverted the ball against his team's right post.
With top-flight survival the priority, it looked like they would have to be content with an unwanted replay in south Wales before List emphatically intervened.
Ahead of next weekend's crunch relegation clash with Huddersfield, Bluebirds manager Neil Warnock urged his players to avoid becoming a cup headline.
He made seven changes to the side beaten 3-0 by Tottenham on New Year's Day, although the first choice centre-back partnership of captain Sean Morrison and Bruno Manga was retained as part of a solid selection.
Gillingham made just one enforced change due to an injury to midfielder Billy Bingham and his replacement, match-winner List, had the first opportunity, turning in space to fire an effort which was comfortably gathered by Smithies.
The visitors began to control proceedings and should have been ahead with 16 minutes played.
A superb cross-field pass from Mendez-Laing found left-back Joe Bennett in acres of space inside the box but his close-range effort was repelled by Gills goalkeeper Tomas Holy, before Joe Ralls' goal-bound follow up was blocked by Alex Lacey.
City defender Morrison was then denied by an excellent save from Holy after stabbing towards goal following a Ralls corner as the one-way traffic continued.
For all of their dominance, Warnock's men were given a warning minutes before the break.
Full-back Bradley Garmston produced an inviting cross from the left and unmarked Gills top scorer Tom Eaves – searching for his 16th goal of the season – headed narrowly over.
Gillingham, just a point above the third-tier relegation zone and on the back of successive defeats, remained a threat in the second period.
They should have broken the deadlock in the 58th minute but Josh Parker somehow fired over from close range at the near post following Luke O'Neill's dangerous right-wing delivery.
Cardiff then almost went ahead in fortuitous fashion when the ball ricocheted off Gills defender Zakuani and struck the upright following pressure from City substitute Josh Murphy.
Mendez-Laing later worked space but fired wide and then rattled the frame of the goal from the edge of the box.
The away side, finalists in this competition in 2008, were made to pay for their profligacy in the 81st minute as List made the most of Eaves' ball into the box to powerfully find the net from 15 yards.
The margin of victory could have been greater as Callum Reilly struck the bar in stoppage time, but the Gills hung on to progress to round four for the first time in 15 seasons.
ga('create', 'UA-72310761-1', 'auto', {'name': 'pacontentapi'});
ga('pacontentapi.set', 'referrer', location.origin);
ga('pacontentapi.set', 'dimension1', 'By Ed Elliot, Press Association Sport');
ga('pacontentapi.set', 'dimension2', 'b1914db6-6765-436d-8869-a912827f3564');
ga('pacontentapi.set', 'dimension3', 'paservice:sport,paservice:sport:club-news,paservice:sport:football,paservice:sport:match-reports,paservice:sport:uk');
ga('pacontentapi.set', 'dimension6', 'story');
ga('pacontentapi.set', 'dimension7', 'composite');
ga('pacontentapi.set', 'dimension8', null);
ga('pacontentapi.set', 'dimension9', 'sport:football');
ga('pacontentapi.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'List leaves it late as Gillingham stun Cardiff'});