With the clock ticking down on South Korea's time in the tournament, striker Son Heung-min ran free after a Portugal corner in added time and slipped a pass to Hwang Hee-chan who fired past Diogo Costa to spark wild celebrations.
After the whistle blew, the anxious Korean players gathered in a circle awaiting the end of the Uruguay-Ghana game and exploded with joy when the news arrived that the South Americans had only won 2-0 in their Group H clash.
South Korea had to beat Portugal at the Education City Stadium to stand a chance of going through to the last 16 and their win catapulted them from fourth to second place by virtue of having scored four goals in the tournament to Uruguay's two.
Portugal finished top despite the loss and should avoid facing likely Group G winners Brazil in the knockout stage.
Winger Ricardo Horta had put Portugal ahead with their first goal attempt in the fifth minute when he found himself inside the box and converted a neat cut-back by defender Diogo Dalot.
The Koreans thought they had levelled in the 17th when a close-range shot by defender Kim Jin-su beat keeper Diogo Costa at his right post but the effort was disallowed for offside.
However, they did manage to equalise 10 minutes later through defender Kim Young-gwon who scored after the ball bounced off Cristiano Ronaldo's back following a corner.
Ronaldo, seeking a goal to equal Portugal's overall World Cup record of nine scored by the great Eusebio, had his first chance just after the half-hour mark with a solo effort which Kim Seung-gyu saved and he was in any case offside.
The Portugal captain had another one-on-one with Kim but his effort was too weak to trouble the keeper and he was given a rest in the 65th minute when replaced by striker Andre Silva.