Match ends, Iran 0, Spain 1.
Spain edged out a gallant Iran in an absorbing contest to ensure they will reach the World Cup knockout stage with a draw in their final group game.
The 2010 champions needed a fortuitous Diego Costa goal after half-time, having been frustrated in an opening period in which they had 81% of possession.
Iran, who defended admirably until the ball ricocheted in off Costa, instantly showed more intent and thought they had levelled, only for Saeid Ezatolahi's strike to be ruled out for offside.
Carlos Queiroz's Iran side had gone close through Karim Ansarifard and Mehdi Taremi before the crucial offside call and their endeavour throughout seemed to endear them to the crowd at the Kazan Arena.
They survived a chaotic goalmouth scramble where Gerard Pique somehow failed to turn home from a yard out, but again showed heart and threatened late on, with Taremi heading over when well placed.
Fernando Hierro, installed as Spain manager two days before the World Cup started, knows his side will reach the knockout stage if they draw with Morocco on Monday.
Spain overcome another test
Spain may feel they have faced several noteworthy hurdles already throughout their stay in Russia.
The sacking of coach Julen Lopetegui before the tournament was followed by a last-minute equaliser by Portugal in their opening game. Then came this significant examination.
Spain are accustomed to dominating possession against sides content to soak up pressure, but Iran's deep 4-5-1 set-up in the first half afforded them only one shot on target. Costa cut an isolated and frustrated figure, with 12 first-half touches.
Iran set a record of 1,121 minutes without conceding a goal in qualifying and only after the break did Spain begin to find holes in a well-drilled defensive block, with Sergio Busquets forcing a fine save and Pique unable to flick home in the six-yard box.
Hierro's side were typically neat with the ball - completing 90% of their passes - and their early second-half momentum told, with a Ramin Rezaeian clearance hitting Costa and finding the corner of the net. It was Costa's ninth goal in his past nine international starts.
The fact he continued to hassle Iran's defenders on a night when he was so often crowded out of the game is to his credit and, after scoring twice against Portugal, he looks to have made the lone striker role his own.
Spain top Group B courtesy of having collected fewer disciplinary points than Portugal.
Iran rue missed chances
Several Iran players slumped to the turf at the final whistle, unsurprising given they had pushed one of the tournament favourites so close.
This was their first competitive defeat since the 2014 World Cup and the way they switched from a defensive focus to chase the game after falling behind showed they have more to offer than simply a stiff rearguard.
Ansarifard's lashed volley left David de Gea motionless but found the side netting, while Taremi failed to hit the target with two headers, notably late on when he rose unchallenged.
But Iran will look back at Ezatolahi's disallowed goal as key. He stabbed home from close range, only for the assistant referee - and then the video assistant referee - spotted he had strayed offside when the ball was flicked on.
Ranked 37th in the world by Fifa - 27 places lower than Spain - Iran continued to show grit in denying Pique in an almighty goalmouth scramble but they crucially failed to find the target with their seven shots at the other end.
Queiroz said the Spain match was Iran's "game of the universe". Their fixture in Saransk on Monday now arguably deserves a bigger title.
A win would send them through to the knockout stage for the first time in their history and a draw could prove enough if Spain lose to Morocco.
Man of the match - Isco
'We had one match point' - what they said
Iran boss Carlos Queiroz: "We showed that we were ready to suffer and ready to compete.
"There's no doubt Spain play wonderful, stylish football but we deserved more for the way we played.
"We will learn a lot from this game. If you think of it like tennis, we had one match point today and we will have another against Portugal. Everything is still open. We are still alive and still dreaming."
Spain boss Fernando Hierro: "What I can say is that we have three more points. We knew it was going to be very difficult and, sure enough, it was a very complex game.
"There were times in both halves when things were tough. During the break, we knew we had a plan and we carried it out - my players did what they had to do.
"Iran are a strong team and it's very tough to score against them. We knew how hard it would be. But once again my players have given everything."
Former Chelsea striker Chris Sutton on BBC Radio 5 live: "Iran had a game plan and they sat deep and let Spain come on to them.
"But in a funny way, Spain's goal gave Iran belief, because that's when they really went for it.
"They gave absolutely everything and I felt so sorry for them lying down on the pitch at the end."
Spain find a 1-0 win again - key stats
- Iran are without a win against European opposition at the World Cup, having lost six of their seven fixtures (W0 D1 L6).
- There have been no goalless draws in 20 games at the 2018 World Cup - the last time this happened was in 1954 (there no 0-0 draws in the 26-game tournament).
- This was the ninth 1-0 win at the 2018 World Cup, one more than the 2014 World Cup group stages.
- Spain have won each of their past five World Cup matches when they have been drawing 0-0 at half-time, all by a 1-0 scoreline.
- Iran did not manage a shot on target for the first time in 14 World Cup games.
- Diego Costa scored with each of his first three shots on target at World Cup tournaments for Spain. He attempted one more after his goal.
- 3Haji SafiSubstituted forMohammadiat 69'minutes
- 9EbrahimiBooked at 90mins
- 11AmiriBooked at 79minsSubstituted forGhoddosat 86'minutes
- 10AnsarifardSubstituted forJahanbakhshat 74'minutes
- 1De Gea
- 11VázquezSubstituted forAsensioat 80'minutes
- 6IniestaSubstituted forKokeat 71'minutes
- 19Diego CostaSubstituted forRodrigoat 89'minutes
- 10Thiago Alcántara
- 17Iago Aspas
- Andrés Cunha
- Shots on Target
Second Half ends, Iran 0, Spain 1.
Omid Ebrahimi (Iran) is shown the yellow card for a bad foul.
Rodrigo Moreno (Spain) wins a free kick on the right wing.
Foul by Omid Ebrahimi (Iran).
Attempt missed. Sardar Azmoun (Iran) header from the centre of the box is close, but misses to the left. Assisted by Ramin Rezaeian with a cross.
Substitution, Spain. Rodrigo Moreno replaces Diego Costa.
Sergio Busquets (Spain) wins a free kick in the defensive half.
Foul by Saman Ghoddos (Iran).
Substitution, Iran. Saman Ghoddos replaces Vahid Amiri.
Foul by Diego Costa (Spain).
Vahid Amiri (Iran) wins a free kick in the defensive half.
Isco (Spain) wins a free kick in the defensive half.
Foul by Omid Ebrahimi (Iran).
Attempt missed. Mehdi Taremi (Iran) header from very close range is just a bit too high. Assisted by Vahid Amiri with a cross.
Offside, Spain. Diego Costa tries a through ball, but Isco is caught offside.
Substitution, Spain. Marco Asensio replaces Lucas Vázquez.
Vahid Amiri (Iran) is shown the yellow card for a bad foul.
Daniel Carvajal (Spain) wins a free kick in the attacking half.
Foul by Vahid Amiri (Iran).