Germany came back from 2-1 down to Costa Rica to win 4-2 but were still eliminated from the World Cup as Japan beat Spain.
Germany knew they needed to win the game against Costa Rica and they got off to a perfect start when Serge Gnabry headed home from a superb cross from David Raum.
Leon Goretska then got another header on target, but this time Keylor Navas came up with a reflex save to deny him.
Just after Gnabry had put a shot wide of the post, Costa Rica almost made Germany pay for a number of missed chances, but Manuel Neuer made an excellent stop to deny Keysher Fuller in a one-on-one situation.
Into the second half, and as Japan took a shock lead over Spain, Costa Rica’s Yeltsin Tejeda levelled the scores with his first goal for his country to make the task even harder for Germany.
Hansi Flick’s side fought back as as Antonio Rüdiger hit the post and Jamal Musiala then hit the woodwork twice, going agonisingly close on three separate occasions.
But instead of going ahead themselves, Costa Rica incredibly took the lead through Juan Pablo Vargas.
Just when the evening couldn’t get much crazier, Germany equalised when Kai Havertz found himself unmarked in the box, who then kicked the ball into the ground to bounce it over the Navas.
Navas then pulled an unbelievable save from close range out of the bag on Leroy Sané to keep Costa Rica in the game.
This topsy-turvy game had even more to offer when Havertz had his brace when he converted from a Gnabry cross, and substitute Niclas Füllkrug made it 4-2 right at the death.