A lucky Diego Costa goal handed Spain their first win of the World Cup although dogged Iran came close to causing a major upset on Wednesday.
The victory in Kazan puts the 2010 winners on course for the last 16.
Costa, who scored twice in a 3-3 opening draw with Portugal in Sochi, courted controversy early in the Group B encounter when he stepped on the toes of Iran ‘keeper Ali Beiranvand as he waited to kick the ball out.
His gesture went unpunished, and the Atletico Madrid striker required another stroke of luck on 54 minutes when his shot came off Ramin Rezaeian to beat Beiranvand after he had been sent through by Andres Iniesta.
The entire Iranian bench poured onto the pitch when Saeid Ezatolahi fired an equaliser for the Lions of Persia just before the hour.
But the thousands of Iranian supporters that filled the stadium with the sound of vuvuzelas throughout were left disappointed when it was ruled out for offside.