In the last minute of Spain’s final group game Fernando Hierro and all of Spain’s subs were suddenly off the bench, frantically signalling to their players, a finger raised on each hand, barely able to believe what had just happened and desperately trying to convey the news. Somehow, they did not yet know how, they had done it – or it had been done for them. Not only had they avoided defeat with a late goal, eventually granted by VAR after an agonising wait, but another late goal 1,593km away meant they claimed first place in Group B, technology telling them their destiny, events elsewhere deciding it.

World Cup 2018: Iran close to stunning Portugal but Quaresma goal enough for draw Read more

Although Spain were never really in danger of being knocked out, first place mattered: they now travel to Moscow to face Russia rather than Sochi to play Uruguay and avoid the half of the draw likely to include Brazil, Germany, France and Argentina. “Moscow will be lovely,” Hierro said; whatever it is, it could have been worse. On moments like these fate turns and futures are built. Spain, certainly, may feel like something shifted here tonight. Sergio Ramos called it a “turning point”.

At 2-1 down to Morocco substitute Iago Aspas scored a 92nd-minute equaliser that was ruled out for offside and then the referee, Ravshan Irmatov, consulted the video. All at once Spain’s celebration was cut short and everything on pause, an entire stadium in suspended animation. Minutes passed, silence falling until Irmatov pointed to the centre circle, the goal given. At the same time, everything changed a long way away, beyond their control. Another 92nd-minute goal, this time a controversial penalty for Iran, took Spain from second place to first – and a very different path to the final.

It had seemed so implausible a moment before and for most of the night. For Portugal it was painful and for Morocco cruel again: the portrait of a World Cup at which they deserved so much more. They could barely believe it. Nordin Amrabat spat: “VAR is bullshit” as he departed. Aziz Bouhaddouz said: “We’ve had no luck. We’ve played amazingly. Last week Ronaldo had one chance and scored: that’s why we lost and the refereeing was shit – sorry about my English.”

Quick guide Dramatic night of VAR in Group B Show Hide Iran penalty appeal 74 min: Sardar Azmoun goes down after a challenge from William Carvalho. Iran wants VAR to get involved but to no avail Morocco take the lead 81 min: Youssef En-Nesyri scores with a towering header, beating Sergio Ramos to the ball to connect with Nordin Amrabat’s corner Morocco wasting time 81 min: Munir El Kajoui Mohamedi is booked for time wasting with the Spain players increasingly annoyed with their opponents Red alert for Ronaldo 88 min: The forward looks worried after an elbow on Morteza Pouraliganji but the referee, after looking at a replay, opts for a yellow Spain back on level terms 90+1 min: Iago Aspas scores with a delightful flick. It is first ruled out for offside then, after more VAR involvement, given Iran win penalty and score 90+2 min: Over in Saransk, Iran are given a spot kick after VAR decides that Cédric Soares handled the ball. Karim Ansarifard scores. 1-1 Portugal survive scare 90+5 min: Mehdi Taremi is presented with an excellent chance five minutes in to added on time – but hits the side netting. Portugal survive Photograph: Hector Vivas/Getty Images Europe

If they could not believe it nor could Spain, as delighted as they were relieved. And if a Cristiano Ronaldo goal had sunk Morocco, a Ronaldo missed penalty rescued Spain. So did Aspas. Hervé Renard’s players honoured his promise that they would “roar like lions for the pride of Morocco” coming within seconds of defeating Spain, whose tournament this may be after all. Down after quarter of an hour and again with moments to go, they had their late equaliser but even that was not enough until Karim Ansarifard’s penalty in Saransk.

Iran’s Carlos Queiroz berates Fifa over Cristiano Ronaldo VAR escape Read more

It had been a long, emotional night that began with Sergio Ramos’s error allowing Khalid Boutaïb to race away and score, slipping the ball between David de Gea’s legs and offering competing visions of Spain: deeply impressive at times, deeply vulnerable at others. “We have to be self critical,” Hierro said. “Five goals conceded in three games is not the path. If we let goals in so easily, it will be hard to achieve the objective.”

After falling behind, Spain got a grip, inclined to the left where Andrés Iniesta and Isco combined and accelerated. Isco rolled the ball under his studs, offering it, hiding it, turning away from challenges. Iniesta speeded up but never sprinted; instead, he skated. Outside them, Alba whizzed, legs whirring. Every pass had purpose and Spain soon had the equaliser, the ball moved swiftly through many stations: Iniesta, Isco, Diego Costa, Iniesta, Isco and into the net. But while Spain controlled they remained at risk, a throw-in sending Boutaib away again only for David De Gea to make his first save of the tournament.

At 1-1 at half-time Spain were through but Portugal’s lead meant they trailed their Iberian neighbours and the second half began badly. Gerard Piqué was fortunate not to be penalised for a handball; De Gea punched unconvincingly as M’barek Boussoufa dashed in; and Amrabat crashed an astonishing shot off the bar. All within 10 minutes during which Nabil Dirar’s speed opened Spain up. Meanwhile, in Saransk Ronaldo missed a penalty that would decided this.

World Cup Fiver: sign up and get our daily football email.

Spain responded and became urgent now. Even the subs were quick, leaping off the bench to return the ball. Possession was theirs, the pass count climbing beyond 500 within the hour, but opportunities were few. Isco had a header cleared off the line by Romain Saïss, Piqué nodded wide. Hierro intervened, Marco Asensio and Aspas were introduced. Spain had 15 minutes but needed two goals to win the group. As it turned out, they did not have to get both themselves – and even conceding one did not ultimately cost them, after Fayçal Fajr’s late corner was met with a towering header from Youssef En-Nesyri.

Spain were on course for defeat until Aspas flicked in the equaliser. At first it was disallowed but VAR was called. The wait felt eternal and by the time the goal was given, tension rising, confrontations on the touchline, far away Iran had scored. Fingers were raised, alerting incredulous footballers. Morocco had roared and had frightened them but they had not stopped them.