Spain squeezed 1-0 past dogged Iran in their World Cup Group B encounter on Wednesday thanks to a fortuitous goal from Diego Costa, but the Europeans suffered a string of second-half scares.
The veteran forward notched his third goal in two games when Ramin Rezaeian’s attempted clearance bounced off the Spaniard’s leg and into the net in the 54th minute.
Though Spain had besieged the Iranian goal in the first half, they were on the back foot for parts of the second, with Karim Ansarifard rifling into the side netting, and Saeid Ezatolahi having a goal ruled out for offside by the Video Assistant Referee (VAR) system.
The result left Spain joint top of their group with Portugal on four points, but 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 offside after being reviewed by the video assistant referee (VAR), 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.
The expectation that they would play well back was unfounded, however, even if they kept their shape superbly, restricting Spain to a handful of chances in the first half.
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.