South Korea looked to be heading home from Qatar before Son Heung-min broke free following a Portugal corner and played a perfect pass for Hwang to slot home in the 91st minute for a 2-1 victory.
Following Uruguay's 2-0 win against Ghana, South Korea join the Portuguese - who had already booked their place in the last 16 after winning their opening two fixtures - in the next round having scored more goals than the South Americans.
South Korea, whose manager Paulo Bento watched from the stands following his outburst at English referee Anthony Taylor in their defeat by Ghana, knew only a win would do.
But Bento's men were left facing a mountain to climb when Portugal took the lead with just four minutes and 52 seconds on the clock.
Pepe's long ball over the top was expertly controlled by Manchester United defender Diogo Dalot, who put it on a plate for Ricardo Horta to fire in from close range.
Portugal were bidding to become the first side to win all three group games at this tournament, but following their early strike they were guilty of taking their foot off the accelerator.
After 17 minutes, South Korea had the ball in Portugal's net - only for Kim Jin-su's rebounded effort to be chalked off for offside - but 10 minutes later, they were on level terms.
Cristiano Ronaldo turned his back on a South Korea corner. The ball struck the Portugal skipper on the shoulder, and fell into the path of Kim Young-gwon, who lashed home.
In response, the impressive Dalot tested goalkeeper Kim Seung-gyu from long range, while at the other end, Son's effort went straight down the throat of Diogo Costa.
Just before half-time, Kim was called into action again as he palmed away Vitinha's fizzing effort. Ronaldo - one goal shy of equalling Eusebio's nine World Cup strikes for Portugal - was unable to convert the follow-up header.
That would prove to be Ronaldo's final major contribution of the night after he was withdrawn on the hour mark, with Portugal boss Fernando Santos keeping one eye on the round of 16.
With Uruguay two goals up against Ghana in Group H's other fixture, South Korea's chances of avoiding a third successive group-stage exit remained alive.
Son's deflected strike was comfortable for Costa before the Portugal stopper palmed away Hwang In-beom's 20-yard blast.
As the second half wore on, a jaded South Korea ran out of ideas, and ran out of steam with Portugal on course to see out the contest.
But Min's brilliant run, Hwang's fine finish, and Uruguay's failure to score a third sees South Korea progress in the most explosive of fashions.