Four-time champions Germany sensationally crashed out of the World Cup despite a 4-2 victory over Costa Rica in their last Group E match on Thursday, tumbling out at the first hurdle for the second consecutive time.
Germany had arrived in Qatar determined to restore their tarnished reputation following their shock 2018 group stage exit. Instead they finished third in the standings, level on four points with Spain but behind on goal difference and will return home early once more.
Japan topped Group E with six points following their 2-1 win over the Spaniards and will face Croatia in the last 16 while Spain will take on Morocco. Costa Rica finished last on three points.
On a night of unrelenting drama in the desert near Doha, the Germans struck first with Serge Gnabry in the 10th minute but saw the Central Americans score twice with Yeltsin Tejeda and a Manuel Neuer own goal before a Kai Havertz brace put them back in front.
Fellow substitute Niclas Fuellkrug added a fourth in stoppage time but even that was not enough to prolong their World Cup stay.
It was the first time in their illustrious World Cup history that Germany had failed to win any of their first two group matches and despite bagging a win on their last attempt, they will be departing Qatar with dropped heads.
"There are so many reasons but I am not looking for excuses," said Germany coach Hansi Flick. "In the first half I was disappointed and very angry at my team and how we allowed the opponent to come back.
"We wanted to score three or four goals in the first half but then we made mistakes. If we had converted those chances, 16 of them.
"But the tournament was not decided today for us. We did not have any efficiency at this tournament and that is why we were eliminated."
Germany were teetering on the brink of elimination going into the game after losing their opening group match to Japan and then snatching a 1-1 draw against Spain.
Needing a victory to avoid a repeat of the 2018 debacle, Germany went in search of an early goal to settle their nerves.
Jamal Musiala tested keeper Keylor Navas with a low drive in the second minute while an unmarked Thomas Mueller should have done much better when he was picked out by Joshua Kimmich but he could not keep his header on target.
Gnabry, however, scored with his glancing header in the 10th minute to put them in front.
Costa Rica, needing at least a point to have a chance to progress, rarely crossed into the German half in the first 45 minutes.
The Germans were desperate to make amends for their horrendous start to the tournament and the chances kept coming but once more they failed to convert them, as in the previous two group matches.
They were almost punished when Keysher Fuller benefitted from a double defensive blunder but his shot was tipped over the bar by Neuer, whose 19th appearance at the tournament was a World Cup record for a goalkeeper.
With the group standings flashing up on the big screen of the Al Bayt stadium, Germany gradually grew nervous with Musiala twice hitting the post early in the second half.
Neuer could do nothing 13 minutes after the restart when Tejeda thundered the ball past him on the rebound after he had first saved a Kendall Waston header.
To make matters worse Juan Pablo Vargas then appeared to have bundled the ball over the line in the 70th minute but the effort was later credited as a Neuer own goal.
Substitute Havertz scored twice in 12 minutes and Fuellkrug added another in stoppage time but ultimately it was too little too late for Germany, who will host Euro 2024 on the back of three successive flop shows at international tournaments.