Kim Young-Gwon's 92nd-minute goal, awarded after a Video Assistant Referee (VAR) decision, left four-time winners Germany on the brink of elimination.
Then six minutes into stoppage-time, with Germany goal-keeper Manuel Neuer in possession in the opponents' half, Ju Se-Jong gained control of the ball, launched it forward and Son Heung-Min tapped into an empty net to score the second.
It is the first time since 1938 that a Germany or West Germany side has not advanced beyond the first section of the tournament, as Joachim Low's side - top of FIFA's World Rankings - finished bottom of Group ‘F’.
Sweden finished top of the group, with Mexico second and South Korea third.
Eighty years ago, Germany lost 2-4 in a replay against Switzerland to go out in the first round when it was a straight knock-out tournament, but their 2018 exit was the first time Germany had ever failed to make it through the group stage.
A win for Germany would have edged Mexico out on goal difference - but the drama came at the other end as Kim put the ball into the net, although it was initially ruled out for offside.
However, the VAR review showed the ball had deflected into Kim's path off of a German player - Toni Kroos - and the goal was given.
With Germany desperately looking for a goal to get back in the match, Neuer joined the attack.
But he was caught out as a long ball left Tottenham forward Son with the simple task of walking the ball into the net to spark jubilant celebrations among the Asian side, even though their elimination had already been confirmed.
The Germans will regret their wastefulness in front of goal when the game was goalless.
South Korea's goal-keeper Cho Hyeon-woo made a fine one-handed save from Leon Goretzka's header and Timo Werner volleyed wide from near the penalty shot.
Mats Hummels headed over the top when unmarked six yards out in the closing stages, before South Korea's two late goals.
It means Germany's hopes of becoming the first team to retain the World Cup since Brazil's victories in 1958 and 1962 ended in embarrassing fashion.