Substitute Stephen Ireland scored twice as Stoke pulled off a late comeback to beat Wrexham 3-1 at the Britannia Stadium and avoid being the victims of an FA Cup giant-killing.
The Conference visitors, who had already hit the crossbar through Wes York, looked set to pull off a well-deserved third-round shock when Mark Carrington headed them in front in the 73rd minute.
But their Premier League hosts' blushes were spared as Marko Arnautovic levelled from close-range seven minutes later before strikes from Ireland in the 88th minute and stoppage time saw the Potters through to Monday's fourth-round draw.
Stoke boss Mark Hughes will be pleased his side have progressed but aware of how close they came to complete humiliation against the club he used to go and watch as a boy.
Meanwhile, the Wrexham fans who made the journey to the Potteries - just over 4,000 - will return to Wales disappointed by the way the game ended but proud of a fine performance from their men.
Wrexham had famously caused an upset at this stage of the FA Cup in 1992 when they beat Arsenal 2-1 at the Racecourse Ground.
And they looked keen early on to make an impression here as Jonny Hunt went close with a free-kick before Connor Jennings tried his luck from distance with an effort that was caught by Jack Butland.
Stoke - with a starting line-up showing seven changes from their 1-1 league draw with Manchester United - registered their first attempt on goal in the ninth minute as Phil Bardsley struck tamely to Jonathan Flatt, who then turned behind a Robert Huth header before seeing the same player fire wide.
Mame Biram Diouf miscued a header, looping it over the bar, and Wrexham just about cleared the ball away when Blaine Hudson got in a mix-up with Flatt, nodding to the goalkeeper as he rushed out of his box.
Stoke's first real show of top-flight quality came in the 40th minute when Oussama Assaidi burst into the area and unleashed a fierce effort that deflected behind off Manny Smith.
A subsequent Bardsley strike was blocked and Wrexham then survived another nervous moment involving Flatt as he completely missed with his kick while trying to clear a back-pass, with the ball trickling wide.
Stoke looked to increase the pressure on their opponents after the break, with Marc Wilson sending an attempt wide and Geoff Cameron heading over.
But Wrexham continued to give as good as they got, and after Hunt had a penalty appeal waved away by referee Simon Hooper, York rattled the Potters woodwork with a lofted shot.
That prompted Hughes to throw on Jonathan Walters and Peter Crouch and Stoke immediately appeared more dangerous in attack.
Ryan Shawcross' header went narrowly wide and the two substitutes then combined, Walters providing a cross from which Crouch headed to bring a fine save out of Flatt, before Arnautovic skewed over horribly.
However, Wrexham hit back once again and this time the magic moment did arrive as Carrington converted from Jennings' cross to send the army of away supporters into delirium.
The upset appeared very much to be on, but the Wrexham fans' joy was short-lived as Arnautovic swiftly equalised, slotting in on the follow-up after Flatt parried a Crouch effort.
And Stoke then ruthlessly killed things off in the last few minutes as Ireland - on since the 76th minute - sent one shot bobbling past Flatt before firing in a more powerful effort in the dying seconds.