Japan defeated World Cup-favorite Spain, 2-1, on Thursday in Qatar to win Group E in shocking fashion, cementing their spot in the round of 16. 

Even more surprising was the fact that, at one point in the match, Spain had a chance to be knocked out as well. However, Germany ended up defeating Costa Rica, 4-2, which allowed Spain to move on to the round of 16 due to a goal differential tiebreaker.

So, despite their win, Germany was eliminated from the World Cup and go home very disappointed. 

CLICK HERE FOR MORE SPORTS COVERAGE ON foxnews.1eye.us

Alvaro Morata celebrates goal

Alvaro Morata of Spain celebrates after scoring his team's first goal during the World Cup Group E match against Japan at Khalifa International Stadium in Doha, Qatar, on Thursday. (Khalil Bashar/Jam Media/Getty Images)

As long as Germany won their match, all they needed was Spain to do what many expected — beat Japan. That would have left Japan with just three points in the World Cup, with their only win coming against Germany, and the latter would head on to the round of 16 by one point in the group.  

In the match between Japan and Spain, Japan didn’t start off well, as their opponent got off to their classic, controlled game early and capitalized. 

WORLD CUP 2022: BELGIUM STUNNINGLY BOWS OUT OF TOURNAMENT AFTER CROATIA TIE, MOROCCO MOVES ON

Alvaro Morata got Spain on the scoreboard when he had a perfect header on a cross from Cesar Azpilicueta that went past Japan goalkeeper Shuichi Gonda at the 11th minute. It was textbook Spain soccer, passing the ball meticulously until they found the right moment to strike on net. 

However, Japan wasn’t going to go out quietly. As the second half got underway, Ritsu Doan notched the game at one apiece in the 48th minute, using his left foot to strike the ball past Spain’s Unai Simon in net. 

Leroy Sane with disappointed look

Leroy Sane of Germany reacts during the World Cup Group E match against Costa Rica in Al Khor, Qatar, on Thursday. (Chris Brunskill/Fantasista/Getty Images)

But the decisive goal was a controversial one, and certainly one that Germany will be scratching their heads over. 

Japan’s Kaoru Mitoma apparently saved a through ball that appeared to go over the back line for a goal kick, and Ao Tanaka knocked it in the net for Japan's second goal of the second half.

The rule is the entire ball must be over the line for it to be considered out. Video replay appeared to show that indeed happened, with Mitoma not being fast enough to get the ball back in play. 

But after VAR check, it was determined the ball did remain in play and the goal counted, giving Japan the lead. 

DON LEMON IS RIGHT — US MEN'S SOCCER PLAYERS SHOULD EARN MORE THAN FEMALE PLAYERS: COMMENTARY

Spain didn’t give up, understanding at one point that there was a chance for them to miss the round of 16 and be knocked out, as Costa Rica was leading Germany, 2-1. 

But Germany scored three second-half goals to win their match. It wasn’t enough for them, but it was exactly what Spain needed. 

Spain controlled possession toward the end of the game, with Japan just trying to hold them off to move on to the knockout stage. If they conceded a goal, they would’ve gone home instead of Germany. 

Japan celebrated when the final whistle came after seven extra minutes were added on the clock, while across town, Germany was disappointed, despite the win, after hearing word of their elimination. 

Japan celebrates goal

Japan players celebrate the goal by Ritsu Doan against Spain, tying the World Cup Group E match at 1-1 at Khalifa International Stadium in Doha, Qatar, on Thursday. (Sebastian Frej/MB Media)

CLICK HERE TO GET THE FOX NEWS APP

As Japan and Spain move on, they will await their opponents from Group H and Group G that will play on Friday to round out the group of 16 teams in the knockout stage.