Japan finished at the top of Group E and will next face Croatia. Spain will take on Group F winner Morocco.
Spain and Germany — which beat Costa Rica 4-2 in a simultaneous match — both had four points in the group. But Spain had a superior goal difference.
The group standings bounced back and forth during both matches. Costa Rica was beating Germany at one point. If that result had stood, Costa Rica would have eliminated Spain.
Japan scored twice early in the second half to come from behind and defeat another European powerhouse and make it to the knockout stage for the second straight World Cup. It’s the first time Japan has advanced past the group stage in back-to-back tournaments.
Here’s the timeline of events:
10 mins: Germany know only victory will do and Serge Gnaby gives Hansi Flick’s team the ideal start.
The Germans leapfrog Costa Rica and join Japan on four points.
11 mins: An easy night for the Europeans? Alvaro Morata scores and Spain are comfortable at the top of Group E, with Germany now second.
Half-time: Nothing to see here. Spain and Germany both were leading at the break.
48 mins: Japan equalise – Ritsu Doan, who supplied the assist against Germany eight days ago, scored an equaliser through the hands of goalkeeper Unai Simon.
Japan return to second place, ahead of Germany on the teams’ head-to-head record, with the sides locked on four points, and identical goal difference and goals scored.
51 mins: Japan lead. Lightning does strike twice. Not content with overturning a deficit against four-time champions Germany after half-time, Hajime Moriyasu’s team score their second goal in three minutes, Ao Tanaka, prodding in from close-range, to turn around their contest with the 2010 winners.
Japan surge to the top of Group E, with Spain and Germany separated only by goal difference on four points.
58 mins: Costa Rica draw level. The team that shipped seven goals to Spain showed its mettle when recovering to beat Japan, now they are at it again following Yeltsin Tejeda’s strike.
It is Costa Rica pinned behind Spain on goal difference, with Germany a distant fourth on two points.
70 mins: Costa Rica lead! Just when you thought matters couldn’t further deteriorate for Germany, keeper Manuel Neuer scores an own goal.
The unthinkable is on. Japan still lead the way in Group E and Costa Rica climb to second.
The mighty pair of Spain and Germany are going out.
73 mins: Germany are all-square. Flick’s team equalise courtesy of Kai Havertz.
It’s still a long way back for Germany. They have two points, Japan are away in the distance on six points. Costa Rica and Spain, meanwhile, are together again on four points, with Spain back in the World Cup almost as quickly as they tumbled out of the competition.
85 mins: Germany retake the lead: Havertz scores his second to swing the scoreline back in his team’s favour.
The Germans return to the four-point mark, level with Spain. Costa Rica are the basement dwellers on three points. There’s no budging six-point Japan from the summit.
89 mins: Germany score a fourth. The points are in the bag after late-bloomer Niclas Fullkrug scores his second goal of the tournament.
All German eyes are on Khalifa International Stadium, desperately hoping for a Spanish equaliser, which would enable the 2014 winners to progress on goal difference at the expense of Japan.
90+8mins: Japan win. The full-time whistle sounds and Japan have completed one of modern international football’s most remarkable achievements, finishing ahead of both Germany and Spain after beating both European nations in barely one week.
90+11mins: Full-time and Germany win 4-2, the identical scoreline when the teams met in the opening game of the German-hosted 2006 World Cup.
On this occasion, it isn’t enough for Flick’s disconsolate men. Germany summoned a commendable response after losing to Japan, but a draw with Spain and this goal-laden victory are enough only to finish third in the standings.