BELO HORIZONTE, Brazil — The way Iran was defending, it was always going to take a little magic from Lionel Messi to send Argentina into the second round of the World Cup.

Until stoppage time on Saturday, Messi had been stifled by Iran's solid back line. Then, out of nowhere, the Argentina captain produced something very special, as he has done so many times for Barcelona, by scoring a stunning goal for a 1-0 victory.

Goalkeeper Sergio Romero, who watched the goal from the other end of the pitch, said Messi "rubbed his magic lamp and we won."

Messi was more pragmatic.

"When I saw that I had scored I was very happy, because we were in added time already and wanted to qualify for the next phase," he said.

Argentina coach Alejandro Sabella watched as Iran tightly marked his star player, but said he always had faith that Messi might deliver when it counted.

"Messi continued on throughout the match," Sabella said. "He had perseverance, patience, attitude. He always had an eye for goal in his own way."

It was Messi's third World Cup goal since 2006. The fixture was also significant for him because it was his 88th Argentina appearance, surpassing Diego Maradona's 87.

However, the Group F match had nearly been a disaster for Argentina. Besides defending, Iran also took the match to Argentina in the second half, creating several chances to win it and cause a tournament sensation.

Iran was punished, however, for those missed chances. Messi, getting a rare touch, quickly moved the ball toward his dangerous left foot and fired a curling shot from 20 yards (meters) just beyond the reach of the diving goalkeeper and into the left corner of the net.

"In the first half, we had four or five clear chances to score a goal and in the second half, they complicated things for us with counterattacks," Sabella said. "But having Messi resolved everything."

The goal showed why Messi has been voted world player of the year no fewer than four times.

Up until that point, he had been kept quiet by Iran's stoic defending, while Argentina had at times been exposed to counterattacks.

"It was a difficult game to be honest," Messi said. "They were able to close up at the back, so it was difficult for us to break down the defense. It was very hot for us."

Iran had several chances to win it, especially in the second half. The best of those opportunities came in the 67th minute, when midfielder Ashkan Dejagah's powerful header from close range was tipped just over the bar by Argentina goalkeeper Sergio Romero.

"We know that it would be a difficult, tense match," Romero said. "Thank God I could get my hand on the ball and it didn't go in."

Earlier, lone striker Reza Ghoochannejhad's header from close range was saved by Romero after a cross from the right. He also missed a chance for a late winner when his shot was again saved by Romero.

Iran coach Carlos Queiroz said two people made the difference in the match: Messi and referee Milorad Mazic. Queiroz said the referee should have pointed to the penalty spot when Argentina right back Pablo Zabaleta mistimed his challenge on Dejagah in the second half.

"I hope they don't punish me, but I'm telling the truth: It was a penalty," Queiroz said, stressing that Mazic had a clear view. "The referee played a role in this game.

"Messi was great, he scored the winning goal. The referee, I'm sorry to say, was not."

Before the match, Iran faced criticism for its defensive tactics after a dour 0-0 draw against Nigeria. But before Messi's strike, Iranian and Brazilian fans were singing "Ole, ole, ole, ole, Iran Iran!" in recognition of the team's attempts to score a winner.

But Messi denied Iran what would have ranked as its greatest result by drawing with the former world champions.

Despite the defeat, Iran can still hope to qualify for the second round. Nigeria plays Bosnia-Herzegovina, which lost its opener 2-1 to Argentina, later Saturday.

The victory sent the pro-Argentina crowd into raptures and most of them stayed in the stands at Mineirao Stadium in Belo Horizonte well after the match. They chanted and waved scarves and flags, and cheered highlights — including Messi's goal — shown on the big screens.