A video replay in injury time gave Spain the goal it needed to win Group B at the World Cup.
Spain substitute Iago Aspas scored the late equalizer Monday in a 2-2 draw with Morocco. His clever deflection off a cross from Dani Carvajal was initially disallowed for offside, but the video assistant referee overruled the call at Kaliningrad Stadium. The decision set off a touchline melee among players from both sides.
Another substitute, Morocco forward Youssef En Nesyri, headed in a goal in the 81st minute to give already-eliminated Morocco hope of a victory.
Earlier, a mix-up by Andres Iniesta and Sergio Ramos gifted Morocco its first goal of the World Cup, with Khalid Boutaib pouncing on the loose ball and scoring in the 14th minute. Iniesta made amends five minutes later by setting up Isco at the other end to bring Spain level at halftime.
With Portugal also drawing with Iran, Spain progressed as group winner because it scored more goals and next plays host Russia on Sunday in Moscow, while Portugal plays Uruguay in Sochi a day earlier.
Spain may be through and is now on a 23-match unbeaten run, but it was far from convincing in group play and again displayed defensive frailties to concede twice against a Morocco team that hadn't scored a goal in its two previous group matches.
Earlier in the tournament, Cristiano Ronaldo scored a hat-trick against Spain in a 3-3 draw with Portugal and only managed a 1-0 win against Iran.
Morocco was playing for pride in Kaliningrad and they can leave the tournament having made a point against Spain's selection of stars.
Defending ruggedly and breaking out in fast counterattacks, Morocco was a constant threat and came close to taking the lead earlier when Noureddine Amrabat rattled the goal frame with a powerful shot in the 55th minute that David De Gea could only watch as it bounced down to safety.
De Gea was criticized after his blunder gave Ronaldo one of his three goals in in Spain's draw with Portugal. But he proved his value to Spain in the second half — first denying Boutaib a second goal with a save at the near post and then punching away a dangerous ball in the 50th minute as Mbark Boussoufa tried to reach a cross.
Spain is through as group leader and faces Russia in the round of 16 at the Luzhniki Stadium in Moscow on Sunday. Portugal's 1-1 draw with Iran left Ronaldo's team second and facing a knockout match against Uruguay on Saturday in the next round.
KEY TO SUCCESS
Isco and Iniesta didn't only link up for Spain's first goal. The midfielders combined all over the pitch and Isco was particularly threatening down the wing as Spain pushed forward.
Noureddine Amrabat, who suffered a head injury in Morocco's first World Cup match, showed the intensity that coach Herve Renard wanted from his team as it played its last match of a disappointing World Cup. Amrabat's searing drive against the bar in the 55th minute capped a strong performance.