Spain started slow, with no trouble being posed on either side of the coin.
Iran's Vahid Amiri beat the offside trap on the right but, after getting into a good position where a cross-field pass to the box was needed, opted to shoot hurriedly at David De Gea after 17 minutes.
Three minutes later, La Roja got a free-kick on the edge of the box after a foul on Diego Costa. David Silva took aim but failed to beat Ali Beiranvand, who made a routine save.
Iran kept a firm head on all fronts, despite David Silva’s attempted volley that sailed over the crossbar after 30 minutes.
La Roja did not slow down though and, on the stroke of halftime, Silva combined with Andres Iniesta before seeing his strike deflect wide of the upright.
Beiranvand made himself big minutes after the break as he pulled off a couple of saves to deny Sergio Busquets and Lucas Vazquez in quick succession.
The pressure eventually took its toll as Diego Costa found the back of the net, albeit with the luck of deflection to put his side 1-0 up on 54 minutes.
Iran thought they had pulled a goal back 10 minutes later but Saeid Ezatolahi's strike was ruled out by the linesman for an infringement in the build-up
Trailing in the final quarter of the match, the Iranians still showed their competitiveness and went close to drawing level on a few occasions, with Mehdi Taremi going the closets in the 81st minute by heading over at the far post.
Spain, though, saw out the win to join Portugal on four points at the top of the group following their victory earlier in the day, while Iran are one point adrift ahead of the final round of group matches.