Carlos Queiroz's side produced a defensive masterclass to reduce Spain to nothing more than half-chances during a hugely frustrating opening 53 minutes for the 2010 champions.
Costa - who scored twice in Friday's pulsating 3-3 draw with Portugal - eventually found the breakthrough, though, when Ramin Rezaeian's attempted clearance cannoned off his leg and into the bottom-left corner.
Iran had the ball in the back of the net just eight minutes later courtesy of Saeid Ezatolahi, but their wild celebrations were cut short after referee Andres Cunha was advised by VAR that Rezaeian's vital intervention had been made from an offside position.
Iran's approach was far more positive following Costa's strike, Mehdi Taremi heading just over from close range in what was their clearest opportunity to find an unlikely leveller.
The win moves Spain level on points with Portugal at the top of Group B and they know a draw against Morocco on Monday will be enough to secure qualification for the knockout stages. Iran, meanwhile, face Portugal on the same day needing a win to progress at the expense of Cristiano Ronaldo and Co.
Spain handed a 100th cap to Gerard Pique, with Dani Carvajal and Lucas Vazquez the only new faces from the side that drew against Portugal.
Any thoughts that Iran would be blown away by their more illustrious opponents soon dissipated as their expertly drilled defence comfortably rebuffed wave after wave of Spanish attack in the opening stages.
Fernando Hierro's side had to wait until the 25th minute for their first attempt on goal, David Silva's long-range free-kick comfortably held by Alireza Beiranvand.
The Manchester City midfielder came closer to breaking the deadlock five minutes later, but his hooked volley sailed narrowly over the crossbar from six yards out.
Spain's frustration was in danger of boiling over shortly before the interval when Costa got involved in an unnecessary spat with Beiranvand, although referee Cunha opted not to punish the combative striker.
Iran's resistance was nearly broken twice in quick succession at the start of the second period.
First, Pique's close-range effort was blocked and then Beiranvand palmed away Sergio Busquets' curled effort from the edge of the penalty area.
The Asian side almost scored the most unlikely of openers when Karim Ansarifard's instinctive effort from a corner flashed into David De Gea's side netting.
That near-miss was brought into sharp focus less than 60 seconds later when Costa picked up Andres Iniesta's pass inside the area and saw Rezaeian's attempted clearance ricochet off his leg and past the helpless Beiranvand.
Ezatolahi thought he had pulled Iran level shortly after the hour but his close-range finish after a scramble was ruled out courtesy of VAR after Rezaeian had strayed into an offside position.
Taremi's back-post header fizzed over De Gea's crossbar seven minutes from time as Iran pushed for an equaliser, but Spain held on for a 1-0 win they certainly deserved.
Key Opta Stats:
- Iran are winless against European opposition at the World Cup, having lost six of their seven fixtures (W0 D1 L6).
- There have been no 0-0 draws in any of the 20 games at the 2018 World Cup so far - the last time that this happened was in 1954 (no 0-0 scorelines in the 26-game tournament).
- Spain have won each of their last five World Cup matches when they have been drawing 0-0 at half time, all by a 1-0 scoreline.
- This result means all three matches on Wednesday ended 1-0. The only other days in World Cup history to see three 1-0 wins in a single day were June 25th 1982 and June 23rd 2010.