gap Connah's Quay Nomads made an impressive late comeback to book a place in the fourth round of the Welsh Cup, but Mark McGregor's men were made to work hard for their win against the Welsh League Division Two visitors.
Two changes were made to the side that started the 2-1 league win over Llandudno the previous weekend as Stuart Scheuber came in for the suspended Craig Jones, who was sent off in that game, and Dean Thurston was handed a start with Danny Forde unavailable.
Gary O'Toole's comeback from injury continued with a place on the bench as Chris Herbert continued alongside hit-man Mike Hayes in the Nomads frontline, but it was the underdogs who started the brightest and created the better chances of the first half.
The first real scare to the Nomads' defence came when Craig Davies struck the post from the edge of the box, and Kristian Orchard should have done better than to pull his shot wide of a gaping goal soon after.
Just shy of the half hour mark, the home side responded and Scheuber came close to opening the scoring with a rasping 20-yard drive that flew narrowly past the post.
With half time approaching AFC Porth took a shock, but well-deserved lead when Craig Wells powered home a header from a corner.
Nomads made two changes at the break in an attempt to take control of the game, with O'Toole and Jamie Petrie replacing Herbert and Thurston, but it was the visitors who doubled their lead against the run of play in the 72nd minute - this time Stuart Brock headed in a cross to silence the majority of the home crowd.
But McGregor's side have shown their fight in previous matches and the comeback started when left back Ben Collins smashed home with just eight minutes remaining. Time was running out, but constant pressure in the final third was rewarded in the 88th minute when player-manager McGregor hit a sweet drive into the corner to level the scores.
Extra time saw even more thrilling action as Porth regained the lead when Gavin Cory netted early on, only for O'Toole to hit an immediate reply for 3-3.
Nomads finally took the lead for the first time in the game in the 100th minute when Hayes fired in from ten yards to tally his tenth goal of the season, before the towering Andy Alston completed the scoring with the eighth goal of a pulsating game in the final minute.
Both sides ended the game with casualties as O'Toole saw red for Nomads, and the minnows had two players red-carded in a fiery Cup tie.
But a very relived Nomads held on and were rewarded for their endeavours in the fourth round draw with an away tie against Welsh Premier League side Carmarthen Town.
NOMADS: Terry McCormick, Ben Alston (Tom Baker), Ben Collins, Mark McGregor, Andy Alston, Alan Hooley, Rob Jones, Stuart Scheuber, Chris Herbert (Gary O'Toole), Michael Hayes, Dean Thurston (Jamie Petrie).
Substitutes Not Used: Danny Pinch, Scott Baker.