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

Even more surprising was the fact that, at one point in the match, Spain also had a chance to be knocked out. However, Germany ended up defeating Costa Rica, 4-2, allowing Spain to advance to the round of 16 on goal difference in the tiebreaker.

So despite their victory, Germany was knocked out of the World Cup and she went home very disappointed.

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

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 on December 1, 2022 in Doha, Qatar.
(Khalil Bashar/Jam Media/Getty Images)

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

In the match between Japan and Spain, Japan did not start well, as their opponent came early to their classical game, controlled and capitalized.

WORLD CUP 2022: BELGIUM LEAVES IMPRESSIVE FROM TOURNAMENT AFTER DRAW WITH CROATIA, MOROCCO GOES ON

Álvaro Morata put Spain on the scoreboard when he headed in a cross from César Azpilicueta that beat Japan goalkeeper Shuichi Gonda in the 11th minute. It was Spain’s textbook football, meticulously passing the ball until finding the right moment to strike at the net.

However, Japan was not going to go quietly. As the second half progressed, Ritsu Doan scored the match one apiece in the 48th minute, using his left foot to knock the ball past Spaniard Unai Simon into the net.

Leroy Sane of Germany reacts during the World Cup Group E match against Costa Rica on December 1, 2022 in Al Khor, Qatar.

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

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

Japan’s Kaoru Mitoma apparently saved a through ball that appeared to cross the baseline for a goal kick, and Ao Tanaka slotted it into the net for Japan’s second goal of the second half.

The rule is that the entire ball must be on the line to be considered out. The video replay appeared to show that it did indeed happen, as Mitoma was not quick enough to put the ball back in play.

But after VAR verification, it was determined that the ball was still in play and the goal counted, giving Japan the lead.

DON LEMON IS RIGHT: US SOCCER PLAYERS SHOULD EARN MORE THAN FEMALE PLAYERS: COMMENTARY

Spain did not give up, understanding at one point that there was a chance to miss the round of 16 and be knocked out, as Costa Rica was beating Germany, 2-1.

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

Spain controlled possession towards the end of the game, with Japan only trying to hold them off to proceed to the knockout stage. If they conceded a goal, they would have gone home instead of Germany.

Japan celebrated as the final whistle blew after an extra seven minutes had been added to the clock, while across town Germany was disappointed, despite victory, after hearing the news of their elimination.

Japan's players celebrate Ritsu Doan's goal against Spain, tying the World Cup Group E match 1-1 at Khalifa International Stadium on December 1, 2022 in Doha, Qatar.

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

CLICK HERE TO GET THE FOX NEWS APP

As Japan and Spain advance, they will await their Group H and Group G opponents on Friday to complete the 16-team group in the knockout phase.