Japan completed an incredible turnaround by coming from behind to beat Spain and qualify for the last 16, sending Germany home in the process.
Having beaten the Germans 2-1 in their opening game, Japan looked to be heading out themselves when Spain took an 11th minute lead through Alvaro Morata and were in total control, dominating possession and not giving their opponents a sniff of goal.
With Germany also leading against Costa Rica, Japan were at that point in third place in Group E.
But everything changed in a three-minute spell after the break. Substitute Ritsu Doan, who'd scored in the win over Germany last week, shot home to equalise, and then Ao Tanaka put Japan ahead with a controversial goal, forcing the ball home from close range after Kaoru Mitoma cut back a ball that looked to be over the byline. Spain protested and it took a long VAR check to establish that the whole ball had not crossed the line.
Once ahead, Japan clung on to their lead tenaciously, tackling like demons, blocking shots, and running themselves into the ground.
Mayo Yoshida, the former Southampton defender, played a captain's role, repelling all boarders, and made a last-ditch clearance in the dying minutes of the game.
Goalkeeper Shuichi Gonda also played his part, saving well from Gavi, Nico Williams and Dani Olmo in stoppage time.
At one point, for about four minutes during a crazy second-half, Costa Rica were ahead against Germany, meaning the Spanish were also set to exit the tournament with the two outsiders in first and second positions But Germany did Spain a favour by coming back to equalise and finally win 4-2. But they needed Spain to equalise with Japan, which would have taken the two European superpowers too.
Luis Enrique's side could not find a way through, and after their 7-0 thrashing of Costa Rica in their opening game, which had put them among the tournament favourites, they have dropped five points from two games. Goalscoring was a problem again here last night, as it was against Germany earlier in the week, and Enrique has to find the right balance between dominating possession and creating genuine goalscoring chances. Morata, had nodded home a Cesar Azpilicueta cross for his third goal of the tournament, but he still looks less than lethal and was replaced by Ferran Torres soon after Japan scored.
On the final whistle, the Japanese players, staff and fans celebrated a famous victory. Having won the Group, they now face Croatia in the round of 16 while Spain will play Morocco, surprise winners of Group F.
What a topsy-turvy tournament this is turning out to be.
Gonda 8; Itakura 7, Taniguchi 7, Yoshida 9; Nagatomo 7, Morita 7, Ito 6, Tanaka 6; Kamada 6, Kubo 6, Maeda 6.
Simon 6; Azpilicueta 6, Rodri 6, Pau Torres 6, Balde 6; Busquets 6, Pedri 6, Gavi 6; Nico Williams 6, Olmo 6, Morata 7.
Victor Gomes (S Africa) 6