Japan have produced one of the biggest results of the World Cup to date, beating Spain 2-1 to eliminate Germany and ensure the Blue Samarai top Group E.
Germany needed a win over Costa Rica, which the duly delivered in a pulsating 4-2 thriller, but also had to hope Spain could hold off Japan.
Trailing at the break, Japan score twice within the first 10 minutes of the second half to turn the group on its head.
Germany briefly went behind against Costa Rica, which for a moment had Spain facing the prospect of elimination also, but recovered to claim the win they needed.
But Japan held on bravely to defeat the 2010 champions, ending Germany's tournament in the group stages for the second consecutive World Cup.
Look back at how the action unfolded in our live blog.
Key events
To leave a comment on the blog, please log in or sign up for an ABC account.
Live updates
That's it for this morning
By Dean Bilton
Well that was a big one. I think we were expecting some excitement coming in given how tight the group was, but nobody could have expected that.
In the end, the day belongs to Japan. Spain progress with a whimper, Germany now seem to have officially entered a national footballing crisis and Costa Rica are left to rue the leakiest defence at the tournament. But the Blue Samarai are triumphant, and are enjoying their moment in the sun.
Have a great day, we'll see you back here tomorrow morning.
How Group E finished
By Dean Bilton
After an absolutely incredible morning of football, Japan and Spain progress to book dates with Croatia and Morocco respectively.
Was it in or out?
By Dean Bilton
This was the goal that knocked Germany out of the World Cup and sent Japan through.
Did the ball cross the line here in the build up? One of the universe's great mysteries, we may never truly know.
Germany heading home
By Dean Bilton
They ran out 4-2 winners in the end, but Japan's result means that victory wasn't enough. For the second consecutive World Cup after winning the trophy in 2014, Germany have failed to get out of their group.
FT: Japan win! They go through, and Germany are out!
By Dean Bilton
The World Cup always delivers.
Japan have now beaten Germany and Spain to top Group E and head through to the last 16 of the World Cup. There are tears in the stands and on the pitch, as the Blue Samarai come to terms with the size of their achievement. 1-0 down at half-time, they turned the game around in a matter of minutes and then held on bravely to secure the result.
The winning goal was one of great controversy, and one we no doubt will speak plenty more about, but the result is finalised. Japan and Spain are through, Costa Rica and Germany are out.
Have Spain settled for it?
By Dean Bilton
95': Costa Rica 2-4 Germany -- Japan 2-1 Spain
If Spain finish second in the group (which they currently will), they play Morocco. If they top the group, they would play Croatia.
Maybe Spain would prefer this result?
Into stoppage time
By Dean Bilton
90': Costa Rica 2-4 Germany -- Japan 2-1 Spain
There will be seven minutes added on in Japan-Spain.
Ten minutes added on in Costa Rica-Germany.
Goal Germany! VAR allows Fuellkrug
By Dean Bilton
88': Costa Rica 2-4 Germany -- Japan 2-1 Spain
Initially flagged for offside, VAR has had another look and decided that the goal should be allowed to stand. Fuellkrug was offside when the ball was played, but did not interfere in the play. Sane was onside, and then chested the ball back to Fuellkrug who was clearly on.
Handy goal difference boost for Germany, but it's all on the Spain finish now.
Can Spain find a way through?
By Dean Bilton
88': Costa Rica 2-3 Germany -- Japan 2-1 Spain
They've been probing ever since Japan took the lead at the start of the half, but they've been running into a brick wall and look a little out of ideas.
Technically they don't really need the goal for their own sake, but the Germans will be hoping their pride kicks in and they find an equaliser from somewhere.
Goal Germany! Kai Havertz gives them the lead!
By Dean Bilton
85': Costa Rica 2-3 Germany -- Japan 2-1 Spain
He's been magnificent off the bench, and his second has restored Germany's lead and raised hopes significantly. He ghosted in at the back post, reading the cross better than anyone and tapped in for number two.
But Germany stll need Spain's assistance in the other game. As it stands, they are still going out.
Making sense of it all
By Dean Bilton
80': Costa Rica 2-2 Germany -- Japan 2-1 Spain
As it stands, Japan and Spain are going through.
If Costa Rica find a winner and Japan beat Spain, Costa Rica will go through and Spain and Germany will miss out.
If Germany find a winner and Spain equalise against Japan, they will go through.
Basically, Germany need to start scoring and hope Spain pull something off against Japan.
What a save! Keylor Navas that is incredible
By Dean Bilton
76': Costa Rica 2-2 Germany -- Japan 2-1 Spain
Absolutely mind-blowing. Fuellkrug was all on his own at the back post to finish off a blistering German counter-attack, only for Navas to hurl himself across the goal and deny him WITH HIS HEAD.
The melon of Keylor Navas keeps Costa Rica alive.
Goal Germany! Kai Havertz equalises!
By Dean Bilton
74': Costa Rica 2-2 Germany -- Japan 2-1 Spain
My head's gone here.
A lovely little chipped finish from Havertz over Navas after Fuellkrug flicked him through. It's a goal that doesn't do a whole lot for Germany just yet, but it sure helps Spain out. Now the Germans need them to return the favour.
Goal Costa Rica! I can not believe it!
By Dean Bilton
As it stands, Spain AND Germany are going out!
It was scrambled home from the set piece, and I think Celso Borges got the final touch. Is that the goal that sends Costa Rica to the last 16?
I'm not sure I've seen a more remarkable 15 minutes of World Cup football than what we've just seen.
Germany hit the post again!
By Dean Bilton
67': Costa Rica 1-1 Germany -- Japan 2-1 Spain
It's the phenomenal Jamal Musiala again who whips one from range and strikes the upright. How he hasn't scored tonight I don't know, but for now Germany remain at the very bottom of Group E.
Germany hit the post twice!
By Dean Bilton
62': Costa Rica 1-1 Germany -- Japan 2-1 Spain
First Musiala, then Rudiger. They are responding, but it's goals they need now - and even then it still may not be enough.
Goal Costa Rica! Yeltsin Tejeda! What is happening?
By Dean Bilton
59': Costa Rica 1-1 Germany -- Japan 2-1 Spain
It is BEDLAM in Group E!
Ten minutes ago Germany were sitting pretty, and now they have mountain to climb! The Costa Rican attack was threatening, but the initial header should have been dealt with by Manuel Neuer. Instead he fumbled straight into the path of Tejeda who duly put the chane away.
Suddenly Spain's position in the second round isn't secure either. This is madness.
Goal given! Goal Japan! Japan lead Spain!
By Dean Bilton
52': Costa Rica 0-1 Germany -- Japan 2-1 Spain
Incredible! What a turnaround!
There were millimetres in that decision as the ball was dragged back from seemingly over the goal line, but VAR has decreed that the whole of the ball hadn't crossed the line before it was squared to Ao Tanaka to turn home.
Japan are currently leading Group E, and Germany are on the brink. It's all changed in a matter of minutes.