KAZAN, Russia — Patience is a virtue, and Spain showed plenty of it to overcome a tough challenge from Iran at the World Cup.

During a frustrating evening at the Kazan Arena when the 2010 champions struggled to break through the stubborn Iranian defense, Diego Costa scored on a deflection for a 1-0 win on Wednesday.

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.