KAZAN, Russia -- A scrappy second-half goal by Diego Costa broke Iran's stonewall and lifted Spain to a 1-0 win in a nerve-jangling World Cup clash on Wednesday.
Costa claimed his third goal of the tournament in the 54th minute at Kazan Arena but the striker hardly knew about it, the ball deflecting off his legs from an attempted clearance by hapless Iran defender Ramin Rezaeian.
The result left Spain joint top of their group with Portugal on four points, with Iran close behind on three going into the third and final set of games. After two defeats, Morocco are out.
After a match played out to a deafening blare from vuvuzela horns from a huge army of Iranian fans, Spain will feel relieved to have emerged with maximum points.
Iran were brilliant in defence for much of the night but also made a number of telling incursions.
A goal by Saeid Ezatolahi was ruled out for offside with the video assistant referee (VAR) being used to confirm the call on the field, while Karim Ansarifard had earlier hammered into the side netting.
Iran coach Carlos Queiroz had rung in the changes, dropping captain Masoud Shojaei and forward Alireza Jahanbakhsh to the bench, while recalling holding midfielder Ezatolahi from suspension and promoting Mehdi Taremi.
David Silva sent a free kick straight into the arms of keeper Ali Beiranvand in the 25th minute for Spain's first shot on goal.
Silva was in the thick of it again at the half hour, with a pirouette and a volley over the crossbar at the end of a string of looping headers.
Silva found a rare metre of space just before the break and was denied again by a deflection off a player.
Spain seemed rejuvenated after the interval, with Sergio Busquets unleashing a searing long-range strike that forced Beiranvand into a brilliant double save.
Minutes later, however, Ansarifard latched onto a poor clearance and unleashed a withering shot that fired just wide of the left post.
Costa, who grabbed a brace in the 3-3 draw against Portugal, was in the right spot at the right time, his lucky deflection leaving the masses of Iran fans at Kazan Arena groaning in disappointment.