A fortuitous second-half goal by Diego Costa broke a Persian stonewall and lifted Spain to a 1-0 win over a courageous Iran in a nerve-jangling World Cup clash on Wednesday.
Costa claimed his third goal of the tournament in the 54th minute at Kazan Arena but the striker hardly knew about it, the ball deflecting off his knee from an attempted clearance by hapless Iran defender Ramin Rezaeian.
The result put Spain joint top of Group B with Iberian rivals Portugal on four points ahead of their last match against the already eliminated Morocco.
Iran remain on three points and can reach the knockout rounds for the first time with victory over Portugal.
'Happy with three points'
After a match played out to a deafening blare from vuvuzelas blown by a huge army of Iranian fans, Spain will feel relieved to have emerged with the points and content that they played the better football against Carlos Queiroz's stingy side.
"We were not lying yesterday when we said in the press conference Iran is a tough team," said Spain coach Fernando Hierro, who replaced the sacked Julen Lopetegui only two days before their opening match against Portugal.
"It is very hard to score against them ... We are very happy with three points."
Boasting Asia's meanest defence, Queiroz's well-drilled Iran were typically grudging, but they will again rue the lack of a clinical touch after a number of chances went begging.
They have yet to score a goal off their own boot this tournament and fans will have torn their hair out after Mehdi Taremi headed over the bar from six yards out in the 82nd minute.
We will still fight for our dreams: Iran coach Queiroz
Queiroz was nonetheless proud of his players, and said they would head into the Portugal decider with confidence.
"We go for it, with great belief and great determination to try to win the game," the master tactician told reporters.
"When we arrived, no-one gave us a chance, but we still fight for our dreams."
Hierro brought winger Lucas Vazquez into his starting side in place of midfielder Koke, seeking more dynamism to break down Iran's wall.
But the Persians kept their shape superbly, restricting Spain to a handful of chances from David Silva in the first half.
It was not until the 25th minute that Spain had a shot on target, with Silva sending a free kick straight into the arms of keeper Ali Beiranvand.
Spain pushed hard after the break, with Sergio Busquets unleashing a searing long-range strike that forced Beiranvand into a brilliant double save.
From an unedifying grind, the game suddenly roared into life, and minutes later, Karim Ansarifard had latched onto a poor clearance and fired just wide of the left post.
The Iranian rally faltered when Silva found Costa in the area, and Rezaeian was desperately unlucky that his challenge ended pinging off the striker's knee and into the net.