Germany have been knocked out of the World Cup, with a win against Costa Rica not enough to secure them a place in the last 16.
Hansi Flick’s side came from behind to beat Costa Rica in their final group game 4-2.
On a thrilling night in Qatar, Japan beat Spain 2-1 in the other group game, meaning Germany’s journey was over for the second World Cup in a row.
Japan’s winning goal, which knocked Germany out, was rather controversial, with some believing the ball went out of play before Kaoru Mitoma crossed it to Ao Tanaka, who went on to score.
However, a lengthy VAR check followed the goal and it was ruled in Japan’s favour.
The results mean Japan top Group E, and Spain come second, with Costa Rica also failing to qualify.
Sky Sports’ Charlotte Marsh said: “It’s quite inconceivable that Germany would exit at the group stage in two successive World Cups – but it’s happened.
“It has been a litany of failures at the tournament since their 2014 win in Brazil, but you cannot say that just because of their pedigree, Germany deserved a spot in the knockout rounds.
“Given their chances created – especially against Japan and Costa Rica – they should have cruised into the last 16. But errors in midfield and defence ultimately proved to be their downfall.”
Germany led the game 1-0 at half-time after Serge Gnabry got an early goal, but Costa Rica took a shock 2-1 lead, which temporarily had Germany and Spain heading out of the competition.
But Kai Havertz equalised and then added a third to put Germany back in front, before Niclas Fullkrug netted a fourth.
Japan will now face Group F runners-up Croatia in the last 16, while Spain will go on to play Group F winners Morocco.