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 before the knockout stages started for the second World Cup in a row.
Japan’s winning goal, which effectively knocked Germany out, was somewhat 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, with officials saying the whole of the ball had not crossed the line.
The team’s first goal was scored by Ritsu Doan with a shot from the edge of the box in the 48th minute.
The results mean Japan topped Group E, and Spain came second, with Costa Rica finishing bottom.
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.
The game also saw a woman referee take to the field for the first time in men’s World Cup history.
France’s Stephanie Frappart officiated for the match – and led an all-female on-field team, with Brazil’s Neuza Back and Mexican Karen Diaz Medina chosen as her assistants.
Japan will now face Group F runners-up Croatia in the last 16, while Spain will go on to play Group F winners Morocco.