The four-time title winners have failed to get out of the group stage in Qatar
Japan mounted a stunning comeback win against Spain as both teams progressed to the World Cup knockout stages from Group E, while Germany exited the tournament even though they beat Costa Rica on a night of high drama in Qatar.
Goals in the space of three minutes in the second half from Ritsu Doan and Ao Tanaka completed a remarkable turnaround for Japan as they defeated Spain 2-1 at Khalifa International Stadium.
In the other game of the Group E finale, Germany claimed a thrilling 4-2 win against Costa Rica at Al Bayt Stadium - but it still wasn't enough for the Germans, who finished behind Spain in the standings on goal difference.
Japan progress to the last 16 as Group E winners on six points, head of Spain in second place on four points.
Spain were ultimately indebted to the 7-0 opening game win they racked up against Costa Rica, which ensured they had a comfortably superior goal difference to Germany.
For the Germans, who were tournament winners at Brazil in 2014, Qatar becomes the second successive World Cup which they have exited at the group stage, following their early departure from Russia four years ago.
The Group E standings were finely poised heading into Thursday night, but few would have anticipated quite so many twists and turns unfolding throughout a remarkable denouement.
Spain seemed on course to comfortably top the group when they took the lead against Japan in the 11th minute through an Alvaro Morata header - his third goal of the World Cup.
But the tables were rapidly turned after the break. First, Ritsu Doan rifled in a shot from the edge of the box which Unai Simon failed to keep out in the 48th minute.
Ao Tanaka then put Japan in front when he turned in a cutback from Kaoru Mitoma three minutes later.
A VAR check took several minutes to determine if Mitoma had managed to keep the ball from going out before he turned it back across the box.
The decision appeared to go down to the finest of margins, but the strike was confirmed and Japan were in the driving seat.
After seemingly cruising, Spain suddenly found themselves in trouble thanks to proceedings in the Germany-Costa Rica contest.
The Germans had given themselves hope with a Serge Gnabry goal in the 10th minute, but Costa Rica mounted a comeback through Yeltsin Tejeda and Juan Pablo Vargas to put them 2-1 in front.
At that stage, it was Japan and Costa Rica heading through in first and second place respectively.
But the drama was not done as Germany battled back with a double from Kai Havertz and a late goal from Niclas Fullkrug to earn a 4-2 win.
It wasn't enough, however, as Spain enjoyed a goal difference cushion of five more than the Germans in the Group E standings.
Japan next face Group F runners-up Croatia on Monday.
Spain play surprise package Morocco on Tuesday in their last-16 clash, after the North Africans beat Canada on Thursday to ensure they topped Group F as Belgium were dumped out of the tournament.