Diego Costa scored a scrappy second-half winner to help Spain edge past doughty Iran in a key Group B FIFA World Cup game here on Wednesday.
After a barren first-half where Spain was left frustrated as Iran defended brilliantly, Costa (54th) broke the deadlock albeit in fortuitous circumstances.
Costa's neat turn and quick shot took a deflection off Iranian defender Ramin Rezaeian to beat goalkeeper Alireza Beiranvand.
Iran tried to launch a comeback and almost equalised when Saeid Ezatolahi's goal was correctly ruled out because of offside by Video Assistant Referee (VAR) Vigliano Mauro.
Karim Ansarifard also rifled into the side netting for the Asian side as Spain were on the tenterhooks for most parts of the second-half.
This was Costa's third goal of the tournament after netting a brace in Spain's rip-roaring 3-3 draw against Portugal in the group opener.
Spain is now level on points with Portugal in Group B, while Iran is in third and Morocco are eliminated following their loss earlier in the day.
In need of a win after the draw, Spain had to wait for more than 20 minutes to get their first shot on target.
David Silva, who saw a lot of the ball until then as his team dominated possession, sent a free kick straight into the arms of keeper Beiranvand in the 25th minute for Spain's first shot on goal.
Manchester City's Silva had at least a couple of more chances to draw first blood. First, he fired over the bar at the half-hour mark and in the dying minutes of the half saw his shot bounce just wide of the far post off an Iranian defender.
With just one shot on target, Spain was bottled up throughout the half by a sturdy Iran defence.
Spain looked to up the ante after the change of ends with Sergio Busquets unleashing a rasping long-range strike that forced Beiranvand into a brilliant double save.
Minutes later, Ansarifard latched onto a poor clearance and let loose a stinging effort that fizzed wide of the left post.
Costa then was in the right spot at the right time to swivel sharply and then get the lucky deflection to break Iran hearts.