If they win, they advance to the World Cup's knockout stage.
Costa took his Russian Federation 2018 tally to three goals with the winning strike in a 1-0 victory in Kazan on Wednesday after Ramin Rezaeian's clearance ricocheted in off the striker. In the 56th minute of the match, Diego Costa caught a lucky break as he managed to put a ball behind the back of the net.
For too much of the contest Spain had no cutting edge, with their possession rate hovering around the 80 per cent mark but their threats on Ali Beiranvand's goal remaining close to zero.
They need to try because Costa, who has been at his battering-ram best, might not provide a get-out-of-jail card every time Spain play.More news: Senegal tops Poland amid controversy for first African win
Nacho scored a stunning goal in a 3-3 draw with Portugal last week but also conceded a penalty that Cristiano Ronaldo converted on his way to a hat-trick.
As for the match itself, 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 knee from an attempted clearance by hapless Iran defender Ramin Rezaeian.
Iran did make a further good chance, Mehdi Taremi heading just over, but Spain - who will know and feel like they were in game - hung on. "We are very demanding of ourselves, but every team will suffer".
Yet, whilst the Iranians may have failed to register the win they pushed Spain hard and will consider themselves unlucky with a battling rearguard performance which saw the Europeans struggle to breakdown a resolute Iran defence.More news: Firmino features as Brazil held by Switzerland
Diego Costa's second-half goal sealed a nervy win over Carlos Queiroz's side in a Group B clash at the Kazan Stadium. Iran adopted a more adventurous approach in attack, now that they needed to score at least one of their own.
Queiroz had no complaints about the VAR decision which ruled out Saeid Ezatolahi's strike for offside, preferring instead to rue that it had not been around at the 2010 World Cup when his Portugal were beaten by a contentious Spain goal. A draw will suffice if Iran fail to beat Portugal.
"What game were you watching", Costa replied.
Iran played toe-to-toe with Spain and deserved more from the match, but Spain's central defense made some important stops, got the victor in the second half and held on to move into a tie for first place with Portugal in Group B.More news: Donald Trump's executive order on family separations prompted by disturbing TV images