Germany have been knocked out of the World Cup in Qatar after finishing third in Group E despite a 4-2 victory over Japan.
The elimination on Thursday came as Japan stunned Spain 2-1 in the other match of Group E, a result that handed those two teams a spot in the round of 16.
Germany and Spain both took early leads in their games, in results which would have put Hansi Flick’s side through. But it all changed in the second half, with Japan scoring two quick goals against the Spanish.
Costa Rica also equalised against Germany, who then hit the post three times before Juan Vargas put the Central Americans ahead.
That would have put Costa Rica through at the expense of Spain, but substitute Kai Havertz scored twice and Niclas Fullkrug got another.
It is the second World Cup in a row where four-times champions Germany have been eliminated in the group stage.
The game was also historic as it was the first men’s World Cup game to be refereed by a woman.
Hansi Flick’s side came from behind against Los Ticos to win at the Al Bayt Stadium, but Japan’s shock win over Spain sent them tumbling out before the knockout phase for a second consecutive World Cup.
Japan topped the group on six points, with Spain edging out the four-time world champions on goal difference thanks to their opening 7-0 win over Costa Rica.
Germany’s campaign in Qatar started off with a stunning loss to Japan, despite dominating the contest, as goals from Ritsu Doan and Takuma Asano handed Flick’s side a defeat.
And a daunting match with Spain followed, with Alvaro Morata breaking the deadlock but with seven minutes from their exit confirmed, Niclas Fullkrug equalised to keep hopes alive.
Germany then entered tonight needing victory and a favour from Spain, but despite taking care of business, Doan and Ao Tanaka hit a quick-fire double to earn victory for Japan and secure progress as group winners.