Germany crashed out of the World Cup on a remarkable night of drama despite victory over Costa Rica at Al Bayt Stadium.
Japan’s 2-1 win against Spain – which saw them finish top of Group E – would have eliminated Germany anyway thanks to Spain’s superior goal difference.
Hansi Flick’s side needed victory to give themselves any chance of reaching the last 16, but it was to no avail.
The Germans were in complete control and led through Serge Gnabry’s 10th-minute header only for Costa Rica to turn the match on its head to raise the remarkable possibility of Spain also going out.
Yeltsin Tejeda equalised after German keeper Manuel Neuer pushed out Kendall Waston’s header in the 58th minute, before Juan Pablo Vargas bundled in a second 12 minutes later. At that stage, they were going through with Japan.
It would have capped one of the most astonishing nights in World Cup history, but Germany substitute Kai Havertz restored a measure of normality to proceedings with two clinical finishes to extinguish Costa Rica’s hopes of springing a major shock.
Substitute Niclas Fullkrug added a last-minute fourth to confirm victory, but it will be of no consolation as Germany failed to reach the knockout stage of the tournament for the second time in succession.