KALININGRAD, Russia — It took a video review of an injury-time equalizer to give Spain first place in its World Cup group.
Spain substitute Iago Aspas scored the late goal 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.
"Until the last minute, we weren't sure who was going to finish first and second," Spain coach Fernando Hierro said. "And I have to say we were lucky to finish first."
The decision set off a touchline melee among players from both sides.
Hierro took over as Spain coach on the eve of the World Cup when Julen Lopetegui was fired after taking the job at Real Madrid. Now he is heading to the World Cup's knockout stage.
"Obviously we can improve," Hierro said. "Five goals in three matches, that is not the way forward. That is what I have told my players, and they understand that."
A rare 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 with a clever cut back pass to bring Spain level at halftime.
Youssef En Nesyri then headed in a goal in the 81st minute to give already-eliminated Morocco hope of a victory.
With Portugal also drawing with Iran, Spain progressed as group winner because it scored more goals. Next up, Spain plays host Russia on Sunday in Moscow, while Portugal plays Uruguay in Sochi a day earlier.
"We haven't really won anything yet. It's been a very tough match," Isco said. "Maybe we weren't focused from the very beginning. We needed them to score on us to force us to react."
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.
While Spain controlled the game against Morocco with 68 percent of possession, Isco thinks that Spain can do better.
"Maybe what we're missing to better control the game is more ball possession," the man of the match said. "Maybe that's what's missing. And that's normally something that we do much better."
Morocco was playing for pride in Kaliningrad and they can leave the tournament having made a point against Spain's selection of stars.
"We would have loved to win over Spain," Morocco coach Herve Renard said. "This is why we came here tonight. We suffered, just like any other team who takes on Spain. When you look at the lineup, it's a mix of Real Madrid and Barca, so these are outstanding players."
Defending ruggedly and breaking out in fast counterattacks, Morocco was a constant threat and came close to retaking 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 has now done better than it did four years ago, when as defending champion it crashed out of the World Cup in Brazil at the group stage following defeats to the Netherlands and Chile.
In the round of 16, Spain faces a Russian team that proved in its first two matches that it can slice through weak defenses. Russia scored eight times in its first two matches before falling to a 3-0 defeat to Uruguay earlier Monday.
"We're going to play against the host. They'll have the audience, they're in their home, but in the end, football is played on the pitch," Hierro said.
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.
Hierro insisted that he wasn't aware of who on his staff was monitoring Portugal's match against Iran and that he didn't want his players focusing on that instead of their own play.
"We understood within a couple of minutes what had happened in the other match," he said. "But you're only 100-percent focused on winning your own match."