Argentina needed a stoppage time stunner from Lionel Messi to see of a spirited Iran in Belo Horizonte.
The Barcelona star was kept quiet for the Iranians for large periods, but he found his range two minutes into stoppage time to curl home a terrific effort that ensures Argentina's place in the knockout stages.
Argentina started the game as huge favourites, with Iran expected to struggle against their opponents star-studded attack.
However, the Asian outfit were outstanding, and well worthy of a point which would have kept their hopes of progressing to the knockout stages alive and kicking.
Argentina made hard work of defeating World Cup debutants Bosnia in their opening game last week.
They needed a Messi special to secure a 2-1 win after a Bosnia own goal gave them an early advantage.
But their second group opponents were not handing out any gifts, with Carlos Quieroz's side digging in for a tough afternoon from the first minute.
And come the second half they had several great chances to grab the opening goal, as their much-fancied opponents ran out of ideas.
Argentina dominated possession in the opening period, but were unable to break down the superbly organised Iranians.
Ezequiel Garay and Marcos Rojo should both have hit the target when well positioned, while Man City striker Sergio Aguero had a curling effort tipped wide by goalkeeper Alireza Haghighi.
Iran's only real chance of the half came in the 41st minute when Jalal Hosseini headed over from a corner after escaping his marker.
The Argentines trooped off a the break knowing they should have been ahead, and in the second half Iran came very close to making them pay.
Charlton striker Reza Ghoochannejhad could have given them a shock lead in the 53rd minute, but his close-range header from a decent right-wing cross was well saved by Sergio Romero.
Just 60 seconds later Fulham midfielder Ashkan Dejagah was furious when he was denied a penalty after a challenge from Pablo Zabaleta.
Replays showed the Man City man just about got a toe on the ball, and that near-miss seemed to spark Argentina into life.
Star man Messi weaved his way into a central position and let fly with a shot from 20 yards which whistled past the far post on the hour mark.
But then Iran came bouncing back, as first Ehsan Hajsafi had an effort deflected wide before Dejagah had a headed effort wonderfully tipped over the crossbar by Romero.
Argentina dominated the last 20 minutes, with several efforts testing Haghighi.
And that pressure finally counted in the 92nd minute, as Messi cut in from the right to bend an effort past the goalkeeper into the far corner to give his side a win they scarcely deserved.