Japan produced another upset in a thrilling World Cup to stun Spain with a 2-1 comeback victory and secure top spot in Group E - a result which eliminated Germany.
Spain had looked in total control at half-time after taking the lead through Alvaro Morata’s early header.
Japan, though, turned things around in the space of five minutes at the start of the second half when substitute Ritsu Doan equalised before Ao Tanaka netted another – which was allowed to stand following a lengthy VAR review after the ball had appeared to have gone out of play.
Japan, who had opened their campaign with a shock win against Germany but then were beaten by Costa Rica, almost snatched an early lead when Junya Ito fired into the side-netting.
Spain went in front in the 11th minute when Morata headed in a cross from the right by Chelsea captain Cesar Azpilicueta for his third goal of the tournament.
The Spaniards continued to dominate possession and although it looked only a matter of time before they would open up the Japan defence again, there were no more goals ahead of the break.
Japan coach Hajime Moriyasu made a double change for the second half, with Brighton midfielder Kaoru Mitoma and Doan sent on for Yuto Nagatomo and Takefusa Kubo.
The changes made an instant impact as Japan equalised three minutes after the restart.
Spain were caught trying to play out from the back as Freiburg winger Doan picked up possession just outside the penalty area and drilled a shot past Unai Simon, who could only palm the ball into the top left corner.
Japan completed another remarkable turnaround when they took the lead in the 51st minute.
Doan was again involved as his low cross went right through the six-yard box and was cut back in by Mitoma from the goal-line at the far post, with Tanaka bundling the ball home.
A lengthy VAR check followed and officials eventually ruled the whole of the ball had not crossed the line – a decision which sparked pandemonium among the now jubilant Samurai Blue faithful.
Spain boss Luis Enrique reacted by replacing Morata with Marco Asensio and sending on Ferran Torres for Nico Williams.
Japan created another good opening with 20 minutes left.
Mitoma broke down the left and clipped a pass back across to the edge of the penalty area where Takuma Asano arrived at pace, but the Bochum forward could only skew his shot wide.
Spain pushed for an equaliser and Japan goalkeeper Shuichi Gonda made a smart reaction save to push away a low drive from Asensio before then collecting Dani Olmo’s angled shot at the near post as Japan celebrated another remarkable victory and a place in the last 16.