During a frustrating evening at the Kazan Arena when the 2010 champions struggled to break through the stubborn Iranian defence, Diego Costa scored on a deflection for a 1-0 win on Wednesday.
But Iran will be boosted by their 1-0 triumph over Morocco on matchday one, a win which has seen them top Group B.
The thrilling 3-3 draw with Portugal in Sochi eased concerns that Julen Lopetegui's sudden departure would derail Spain's campaign and reports coming out of the camp indicate an upbeat mood under his makeshift replacement Fernando Hierro. In the more likely situation that Spain secure victory, they will enter their final group encounter in a much more comfortable position for reaching the first knockout rounds.
The victor against Iran means he is one goal behind Portugal star Cristiano Ronaldo in the race for the Golden Boot, but Costa is not focused on individual honours.
Striker Diego Costa did brilliantly in the box to turn his marker but his initial shot rebounded of the legs of the defender and ricocheted off his knee and into the net to give Spain a 1-0 lead.
Then, trailing in the second half, Iran almost equalized when Saeid Ezatolahi had a goal ruled out on video review. Iran was also unsafe on the break, using the speed of its attacking players to threaten the Spanish back four but without creating many real chances.More news: Cavaliers intend to keep Love next season
"But this was our first match point, if we compare this to tennis, our second match point comes against Portugal".
Iran's Saeid Ezatolahi celebrates scoring their first goal with team mates before it was disallowed after a VAR review.
"We can guarantee that we will keep working for our dreams, and our dream is to qualify for the second round".
Taremi had a wonderful chance to level the scores in the 82nd minute after meeting a cross from the left, but Iran's number 17 somehow planted his header over the crossbar from close range.
Spain seemed rejuvenated after the interval, with Sergio Busquets unleashing a searing long-range strike that forced Beiranvand into a brilliant double save. Amiri megs Pique down the left and delivers a luscious cross but one hit with just too much pace, so Mehdi can't get above it. he makes a great connection, but smashes his header just over the bar.
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.