Doha, Qatar - Ritsu Doan and Ao Tanaka earned Japan a stunning 2-1 victory over Spain in World Cup Group E on Thursday as both teams reached the last 16.
Japan topped the standings and will face Croatia next while Spain, which finished level with Germany with four points, advanced on a goal difference and will play Morocco.
Striker Alvaro Morata put Spain ahead in the 12th minute when he headed home Cesar Azpilicueta's cross for his third goal in three World Cup games.
Japan leveled three minutes into the second half through winger Doan who slotted home from just outside the penalty area and midfielder Tanaka scored the winner in the 51st minute, the goal confirmed after a lengthy VAR check.
Germany 4, Costa Rica 2
Germany was knocked out of the World Cup in the group stage for a second consecutive time despite a 4-2 win over Costa Rica on Thursday after the four-time champions were consigned to third in Group E following Japan's victory over Spain.
Germany's Kai Havertz looks dejected after his team won the match against Costa Rica but was eliminated from the World Cup, at Al Bayt Stadium, Al Khor, Qatar, Dec. 1, 2022.
Costa Rica deployed a five-man back line, but Germany still found a way through in the 10th minute when David Raum floated in a cross that was headed home by Serge Gnabry, who restarted the game quickly fearing goal difference being a factor.
But after learning that Japan was leading Spain in the other group game, Germany let their guard down and Costa Rica scored twice with Yeltsin Tejeda arriving late to score the first before Juan Pablo Vargas bundled a second over the line.
Germany's Kai Havertz grabbed a brace after coming on as a substitute to seal the three points before Niclas Fuellkrug added a fourth late in the game, but the final results left Japan at the top of the group while Spain finished second.
Morocco 2, Canada 1
Two first-half goals set Morocco on their way to top place in World Cup Group F but they had to hold on for a 2-1 win over Canada at the Al Thumama Stadium on Thursday after conceding an own goal that kept them nervous through the second half.
Morocco's players throw Coach Walid Regragui into the air after their victory over Canada that put them atop the Group F standings and into the knockout round of the World Cup at Thumama Stadium in Doha, Qatar, Dec. 1, 2022.
Morocco finished on seven points, two more than runners-up Croatia, to advance from the group stages for a second time, 36 years after they became the first African country to do so at the Mexico World Cup in 1986.
A goalkeeping howler allowed Hakim Ziyech to score after four minutes, followed by a second in the 23rd minute from Youssef En-Nesyri, running onto a superb long pass from Achraf Hakimi.
But Nayef Aguerd stuck out a toe to deflect a cross from Sam Adekugbe into his own net five minutes before the break to offer already-eliminated Canada a chance to get back in the game and win a first World Cup point. Canada came close to a second-half equalizer but proved unable to make the breakthrough.
Croatia 0, Belgium 0
Croatia eased into the last 16 of the World Cup after holding a stuttering Belgium to a 0-0 draw on Thursday, sending their European rivals' 'golden generation' out of the tournament with barely a whimper.
Belgium's Timothy Castagne is dejected as his team was eliminated from the World Cup after a 0-0 draw with Croatia at Ahmad Bin Ali Stadium in Al Rayyan, Qatar, Dec. 1, 2022.
The result saw Zlatko Dalic's men qualify in second place in Group F behind Morocco, who beat already eliminated Canada 2-1 in the other game to secure top spot.
Neither side had a shot on target in a dour first half and Belgium brought on striker Romelu Lukaku at the break, but it was Croatia who sprang into life, with Marcelo Brozovic and Luka Modric drawing saves from Thibaut Courtois in quick succession.
Lukaku rattled the post with a fierce shot from close range on the hour as Belgium pushed desperately for the goal that would send them through, but Croatia held firm to extend their unbeaten run in the World Cup group stage to six matches.