Costa scored in the 54th minute after being set up by Andres Iniesta. The powerful striker turned in the area and took a shot that deflected off Ramin Rezeian before bouncing back onto Costa's knee and into the net.
It was far from a beautiful win, but the goal was enough to make Spain coach Fernando Hierro smile. "We have four points," Hierro said. "We were happier after the match against Portugal, but we only had one point."
Spain and Portugal lead Group B with four points each following their 3-3 draw and 1-0 victories. Iran has three points, but Morocco has been eliminated. Costa, who scored twice against Portugal, has three goals at this year's World Cup, trailing Cristiano Ronaldo by one. He also has nine goals in his last nine starts for Spain.
He only had one chance against Iran, and he converted it. "It's going be tight (with Ronaldo)," Hierro said. "I know Diego is really committed, he has scored three goals in three matches. He can do better, he works hard, he is fighting both at the back and at the front."
Facing a very compact Iranian team that came out to defend, Spain pressed high and controlled much of the game but found it difficult to threaten against Iran's 10-man defense. Spurred on by their vociferous fans, Iran's imposing players did well to handle Spain's attacks. Iran was also dangerous on the break, using the speed of its attacking players to threaten the Spanish back four but without creating many real chances.
Spain was mostly dangerous from set-pieces, including in the 25th minute when a free kick from David Silva that took a deflection was stopped by Iran goalkeeper Ali Beiranvand. Spain continued to apply strong pressure in the second half and Beiranvand stopped a strike from Sergio Busquets in the 49th minute with a superb one-handed diving save. He then palmed the rebound away before Lucas Vazquez could get to the ball.
Hierro's players were almost caught against the run of the play when Karim Ansarifard unleashed a powerful strike that ended up in the side-netting following a long thrown in. Then, trailing in the second half, Iran nearly equalized when Saeid Ezatolahi had a goal ruled out on video review.
Iran continued to push hard and managed to challenge with some fast counterattacks. Spain was lucky not to concede toward the end as Mehdi Taremi connected with a cross from Ansarifard, but his header from close range went over the crossbar.
GROUP DYNAMICS First place in the group could be decided by goal difference. Spain will face Morocco in its final match on Monday in Kaliningrad, while Portugal plays Iran in Saransk on the same day. But with three points, Iran has still a chance to qualify for the knockout stage. The Iranians will need to beat Portugal to advance.
KEYS TO SUCCESS It's not just slick play within the Spain team. With a superb display of collective grit, the Spanish showed they are as united as ever despite the turmoil created by the firing of coach Julen Lopetegui on the eve of the tournament.
Spain is now unbeaten in 22 matches, with 15 of those wins. The team's last loss was against Italy in the round of 16 at the 2016 European Championship. Iran was dangerous from set pieces and its restless defensive display was impressive. The team also created a few excellent chances, including that missed header from Taremi in the 83rd minute.
ANGRY COSTA Named the man of the match, Costa took umbrage when he was asked why he played aggressively. Costa had a bust-up with Beiranvand toward the end of the first half after the Iran keeper went down in the box. It appeared that Beiranvand exaggerated his pain after Costa stood on his foot.
"What game were you watching," Costa replied. "They were provoking us, and we were on the grass all the time. You can't just say that because it's your national team playing."
More AP World Cup coverage: https://apnews.com/tag/WorldCup