Argentina had been thankful to three fine second-half saves from goalkeeper Sergio Romero just to be level heading into stoppage time, while Iran had also had a strong penalty appeal waved away when Pablo Zabaleta appeared to foul Ashkan Dejagah inside the area.
However, despite having endured a quiet game by his standards, Messi produced a moment of magic when his side needed it most to register his second goal of the tournament.
Argentina now lead Group F with maximum points from two games and will be confirmed as group winners should Saturday's late game between Nigeria and Bosnia Hercegovina fail to produce a winner.
However, after another underwhelming performance, Messi assured there is more still to come from his side
"We are not showing what we can do, but with a run of games I think we will get there.
"We are the first ones to know we have not reached the level we would like," said the Barcelona forward.
"They made the game very difficult for us," admitted Argentine boss Alejandro Sabella.
"Messi was marked very tightly, but he showed perseverance, patience, attitude and always looked for the goal. He never gave up."
- "It was a penalty" -
Iran coach Carlos Queiroz also praised Messi's match-defining contribution, but claimed his side had been undone by Serbian referee Milorad Mazic's decision not to award a penalty when his side were on top in the second-half.
"Messi was fantastic, but the referee wasn't," said the former Real Madrid coach.
"I don't understand it, he had to have seen it was a penalty. He was five metres away, there is no way he couldn't have seen it.
"I have the right to say this and I only hope I am now not punished for telling the truth."
Sabella had resorted to the 4-3-3 system preferred by Messi with the four-time World Player of the Year joined by Gonzalo Higuain and Sergio Aguero in attack.
However, despite enjoying the vast majority of possession in the first-half, La Albiceleste struggled to create chances from open play against a well-organised Iranian defence.
The first opening fell to Higuain from a fine pass by Fernando Gago, but Iranian goalkeeper Alireza Haghighi bravely smothered the ball at the Napoli striker's feet.
Angel di Maria and Messi, from a free-kick, then fired over from the edge of the area. Argentina were having some joy from set-pieces and Marcos Rojo and Ezequiel Garay should have done better when they failed to hit the target from close range from fine deliveries by Messi.
Iran were also dangerous from set-pieces, though, and they could even have gone ahead before the break when Jalal Hosseini headed just over from a corner.
It was the Asian side who threatened again at the start of the second period as Reza Ghoochanneijhad forced a fine low save from Romero with a flashing header at the near post, before Dejagah's appeals for a penalty were turned down when he tumbled in the area under pressure from Zabaleta.
Messi then had his first clear chance of the game as he raced onto Javier Mascherano's pass but curled the ball just wide of the target.
Romero was forced to come to his side's rescue again moments later when he got fingertips to a fine header from Dejagah to turn the ball behind and the Monaco stopper denied Reza once more as Iran threatened to nick all three points on the counter-attack two minutes from time.
Instead it was Argentina who snatched victory at the last as Messi created the half yard of space he needed on the edge of the area before leaving Haghighi with no chance as he curled the ball just inside the far corner with his favoured left foot.