They must now go on to beat Portugal in their final game to be in with a chance of progressing from Group B.
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.
Iran did not let their heads drop, however, and thought they had equalized soon after through Saeid Ezatolahi when he turned home a free-kick into the box, only for the VAR to rule there had been an offside in the build-up.
Trailing in the final quarter of the match, the Iranians still showed their competitiveness and went close to drawing level on a few occasions, with Mehdi Taremi going the closets in the 81st minute by heading over at the far post.
Spain played a 3-3 draw against Portugal on Friday.
La Roja did not slow down though and, on the stroke of halftime, Silva combined with Andres Iniesta before seeing his strike deflect wide of the upright.
Indeed, despite having the worse season in Madrid this past term, Asension looked to be what was needed more so on the night, a more direct runner of the ball with a better eye for goal.
78th minute, THROUGH PASS: Collects the ball with plenty of space down the left and finds Costa with a delicious ball around the corner of the Iran defence.
Iran famously picked up the victory in the World Cup for the first time since 1998 against Morocco.
Many would say that Iran has been hard to defeat for a few years but the Iranians have never faced any team ranked in the top 20 in the World Cup. Cautious optimism will be the order of the day, and Iran boss Carlos Queros side will be looking for a similarly defensively strong performance against one of the favourites for the World Cup. Labelled the "Iranian Messi" Azmoun will be facing Spain in the familiar surroundings of the Kazan Arena. He also has nine goals in his last nine starts for Spain.
The FIFA World Cup 2018 Iran vs Spain match will take place on Wednesday, June 20, 2018.