It looked as if South Korea would not find the goal they needed to qualify for the round of 16 on goals scored, but Hwang Hee-chan appeared in the first minute of injury time to put his side through after Kim Young-gwon had equalised following Ricardo Horta's opener.
"We're very happy, we deserved it for everything we did in the three games," South Korea assistant coach Sergio Costa, standing in for suspended boss Paulo Bento, said. "We dedicate this victory to all the South Korean people who support us a lot.
"We'll celebrate a little, rest and tonight we'll see our likely opponent. Then, like all games, we'll prepare it in the same way -- knowing strengths, weaknesses, adjusting to our characteristics and preparing the game plan."
Portugal took a quickfire lead in the fifth minute when Horta turned home following good work from Diogo Dalot down the right-hand side -- scoring on his major tournament debut.
The underdogs had their equaliser in the 27th minute, however, when Kim steered a loose ball past Costa after a corner bounced off Cristiano Ronaldo.
And they found the winner when Son Heung-min led a brilliant counter-attack from a Portugal corner which was expertly finished by Hwang.
"Things didn't go well and the responsibility is mine, obviously," Portugal coach Fernando Santos said.
"In the second half the team had many ups and downs. In the first half, we didn't let them counter-attack, but in the second, the ball circulated slower.
"It had already happened with Serbia [Portugal conceded a stoppage-time goal to them in World Cup qualifying which meant they dropped to the play-offs] and the players know perfectly well that it can't happen, they [have been] more than warned [about] this. It cannot happen."
Information from ESPN's Adriana Garcia contributed to this report.