A brilliant 83rd-minute strike from Chris Martin saw Bristol City through to the FA Cup fourth round with a 2-1 victory over impressive Portsmouth at Ashton Gate.
Famara Diedhiou fired the Sky Bet Championship side in front after 19 minutes with a sweet left-footed strike from just outside the box after exchanging passes with Hakeeb Adelakun.
But League One Pompey hit back on the stroke of half-time when Andrew Cannon pulled the ball back from the left and right-back Callum Johnson slotted a low drive past Dan Bentley from 15 yards.
Portsmouth were looking the more likely winners when Martin found the roof of the net with a superb right-footed shot on the turn from 20 yards to settle the outcome.
Even then, the underdogs were denied a last-gasp equaliser when Bentley saved superbly from substitute Jordy Hiwula.
City head coach Dean Holden gave a rare start to winger Adelakun, back from a loan spell at Hull, and paired powerful strikers Diedhiou and Martin up front for the first time. Alfie Mawson returned to defence after a long injury lay-off.
Portsmouth boss Kenny Jackett recalled former Bristol Rovers defender Lee Brown and winger Michael Jacobs, with loanee Cameron Pring having returned to Bristol City and Ronan Curtis feeling unwell. It was Pompey's first game for three weeks due to Covid-19 and the freezing weather.
Holden's men made the brighter start and almost took a seventh minute lead when Martin ran onto a Diedhiou pass and saw his shot from a narrow angle blocked by the legs of Portsmouth goalkeeper Craig MacGillivray.
Diedhiou's goal gave City a deserved lead, but Pompey reacted well and John Marquis had a close range shot blocked.
Martin was wide with a free-kick and the home side were looking comfortable with their lead when Johnson struck back in first-half stoppage time.
Jackett made a change at half-time, sending on Jack Whatmough for centre-back Rasmus Nicolaisen, who had been booked for one challenge on Antoine Semenyo and lectured over another.
City began the second half with some sloppy passing errors and Bentley had to dive to save a low 25-yard drive from Tom Naylor.
Semenyo began to threaten for the Championship side. He had a low shot saved by MacGillivray on the hour and another effort deflected over.
But Pompey produced the best move of the game in the 70th minute when some slick passing ended with Naylor's shot being saved by Bentley. Soon afterwards, Bentley was in action again to deny Jacobs.
Portsmouth were looking increasingly confident as Bentley made another stop from a header by substitute Ellis Harrison.
And after Martin's strike from the blue, City's goalkeeper made his best save of all to keep out Hiwula's close-range shot, which proved to be the last kick of the game.