The Iranians entered the match as underdogs, but had a World Cup win under their belts following their opening game win over the Moroccans.
After a goalless first half in Kazan in which the Iranians frustrated Spain, the resistance was finally broken on 54 minutes through a fortuitous goal from Diego Costa, when the ball bounced back off Ramin Rezaeian, into the Spain striker and on into the net.
It was Costa’s third strike of Russia 2018, but few will be as lucky during the whole tournament.
Iran did not let their heads drop, however, and thought they had equalized soon after through Saeid Ezatolahi when he turned home a free-kick into the box, only for the VAR to rule there had been an offside in the build-up.
Spain came close to doubling their lead after a goalmouth scramble, but Iran survived to fight until the final whistle in front of 42,000 fans in Kazan.
Carlos Queiroz’s team fashioned chances of their own, and came close through Madhi Taremi who put a powerful header over when well placed just 10 minutes from time.
Spain ultimately closed the game out despite being far from their best, moving them up to four points in Group B, level with Cristiano Ronaldo's Portugal on points and goal difference.
Despite the defeat Iran can still qualify, but will likely need to pull off a shock and beat Portugal in Saransk on Monday.
Spain play Morocco in their final group game in Kaliningrad, with the Moroccans knowing they are already out having lost their two games so far.