Having scraped out of their group in third place, Fernando Santos's team somehow held the far more energetic Croatia goalless deep into stoppage time in Lens then, having just been saved by a post, they broke away for Ricardo Quaresma to head a breakaway, counter-attacking winner.
Minutes later the final whistle to this second-round tie prompted delerious Portuguese celebrations while the baffled, bemused and beaten Croat players wandered around the pitch in a fog of incomprehension, their eyes glazed like zombies.
Portugal, somehow, thus continue to a quarter-final against Poland next Thursday in Marseille. Croatia, their campaign tarnished by their fans' outbursts, fly home wondering where it all went wrong.
The match itself produced a modicum of chances. Croatia were possessed of more energy but Portugal, while looking leg-weary, proved themselves perfectly capable of contesting the physical battle.
Cristiano Ronaldo was little in evidence, slowed by injury and restricted to gestures of impatience and frustration whenever a putative attack was halted by Croat resistance.
Extra-time produced more drama than all the previous 90 minutes.
In the first 15 minutes Nikola Kalinic, the Fiorentina striker, shot wastefully wide after a lucky bounce fell into his path as he surged forward; Brozovic was similarly off target on the break. At least that was two more goal efforts than Portugal managed.
After the turnaround Vida headed over from a left-wing corner which goalkeeper Rui Patricio missed then Kalinic drove the ball across the face of a gaping goal without anyone being close enough to apply a finishing touch.
Perisic rose to head against a post but, while Croatia were cursing their luck, Portugal broke away.
The brilliant young Renato Sanches burst through the centre, passed left to Nani whose cross to the right found Ronaldo striding in on goal. Keeper Danijel Subasic reached a hand to the Portugal captain's shot but the ball merely sat up conveniently for Quaresma to head in from close range.
Quaresma's goal earned a meeting with Poland who had defeated Switzerland 5-4 in a penalty shootout after a 1-1 extra-time draw in Saint-Etienne.
Granit Xhaka, in the middle of leaving Borussia Monchengladbach for Arsenal, was the luckless one player to fluff his kick, pulling Switzerland’s second kick well wide of not keeper Lukasz Fabianski but also of the keeper’s right-hand post.
Poland’s decisive last kick was lashed up into the roof of Yann Sommer’s net by Sevilla’s Grzegorz Krychowiak.
The midfielder described himself as being “on cloud seven” in the euphoric moments after the match. Cloud Nine is presumably being saved for later in the tournament.
Poland won courtesy of a more solid team performance over the 120 minutes. Switzerland ultimately paid the price for their flight home from a fragile first-half performance in which they allowed Poland to take the lead just before half-time through Jakub Blaszczykowski,
After that the Swiss were always in pursuit of the game, rather than ever in command of it. Xherdan Shaqiri, with spectacular overhead scissors kick from the edge of the penalty box, equalised to send the tie into stoppage time. He also put away his penalty. But Xhaka had already missed his effort and Poland were far too cool and clinical.