Iran's opening victory over Morocco means they trail the two Iberian powers by a single point in Group B with all to play for against the European champions in Saransk next Monday.
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.
Saied Ezatolahi thought he'd equalised midway through the second half but, to Spain's relief, the goal was chalked off for offside.
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.
Queiroz said he was proud of the performance of his players and insisted they will continue to confound expectations as they head into their final group game against Portugal.
Fernando Hierro's side had to wait until the 25th minute for their first attempt on goal, David Silva's long-range free-kick comfortably held by Alireza Beiranvand.
Don't miss a moment of the World Cup!
"What game were you watching", Costa replied. We all know it's tough to play them.
Spain chalked up the 1-0 win over Iran at Kazan Arena thanks to a strike from Diego Costa. Spain may be the favorite, but there's no reason Iran can't pull off an upset if they're able to disrupt the Spanish offense.
It was far from a attractive win, but the goal was enough to make Spain coach Fernando Hierro smile.
While only one of them was a clear-cut opportunity Silva dropped deeper after the break and looked to gather the ball further away from goal.
45+2' - First sight of goal for Spain!
Isco and Andres Iniesta's magic has probed the Iran defence, but a series of last ditch tackles have been enough to keep the game goalless at the Kazan Arena.
Which channels will show FIFA World Cup 2018 Match-20 between Iran vs Spain coverage?