Deflected goal off Costa’s leg gives Spain first win of the tournament after strong show by Iran.

Follow Al Jazeera’s coverage of the World Cup 2018 here.

A scrappy second half goal by Diego Costa broke a Persian stonewall and lifted Spain to a 1-0 win over a courageous Iran in a nerve-jangling World Cup clash.

Costa claimed his third goal of the tournament in the 54th minute at Kazan Arena on Wednesday 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 offside after being reviewed by the video assistant referee (VAR), while Karim Ansarifard had earlier hammered into the side netting.

https://twitter.com/FCNazalona/status/1009524031534649344?ref_src=twsrc%5Etfw

That was a battle. Iran are going to give Portugal problems. That's a proper play-off. They're a good side. — Miguel Delaney (@MiguelDelaney) June 20, 2018

Iran & Morocco have been really unfortunate today. Both deserved something from their games. — United Religion (@Unitedology) June 20, 2018

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.