Lionel Messi set the two-time winners on their way with his first goal in Russia but Victor Moses equalised from the penalty spot and as time ticked away the increasingly ragged South Americans appeared to be heading home.
But Rojo made a surprise appearance in the box to turn home a cross from Gabriel Mercado with a crisp side-footed volley in the 86th minute to send the Argentine fans in Saint Petersburg, including legendary 1986 World Cup winner Diego Maradona, into raptures.
A highly emotional Maradona rushed to the front of the VIP box where he was watching and gave a one-fingered salute with both hands and shouted an obscene insult.
Maradona later fell unwell and a video emerged of him being helped by two people in his entourage into a chair. Photographs showed the 57-year-old being tended to by paramedics, although Argentinian daily Ola reported he later went to his hotel.
Argentina’s escape came after Rojo came close to having a penalty awarded against him for handball minutes earlier until he was saved by a controversial VAR review.
“It is marvellous to have won it in this manner. It is a deserved joy,” Messi said in quotes on Argentina’s official Twitter account.
“We knew God was with us and wasn’t going to let us go out.
“I thank all the fans that are here, for all their sacrifice and to all those in Argentina that were always with us.”
Argentina were held by Iceland in their tournament opener and then humiliated 3-0 by Croatia, putting the 2014 finalists on the brink of a first-round exit.
Their struggles came after their pre-tournament preparations were racked by controversy and poor form, coupled with a reliance on an ageing, unbalanced squad.
The Argentine federation was even forced to confirm that Jorge Sampaoli would continue for the final group game amid rumours of a rift between players and coach.
At the drama played out, 1,500 kilometres away in Rostov-on-Don Croatia snuffed out the challenge of Iceland, scoring late through Ivan Perisic to seal a 2-1 win and complete a perfect group stage.
Croatia will face Denmark in the first knockout round in Nizhny Novgorod on Sunday (July 1) but Nigeria and Euro 2016 surprise package Iceland will head home.
Croatia took the lead thanks to a slick second-half volley by Milan Badelj. Gylfi Sigurdsson equalised from the penalty spot before Perisic struck late.
Croatia were already through to the last 16 and coach Zlatko Dalic rested most of the side that thumped Argentina 3-0, with only captain Luka Modric and the winger Perisic keeping their places.
“Our goal is achieved,” said man-of-the-match Badelj. “We are top of the group and we are ready to compete in the second round of the World Cup.
“Now we can concentrate on preparations for the knockout stage. This is a big new win for Croatia. There is no special celebration, let’s go further, step by step through the tournament.”
Earlier, France and Denmark produced the first goalless match of the tournament in front of 78,000 spectators at the Luzhniki Stadium in Moscow.
Didier Deschamps rested goalkeeper Hugo Lloris and midfielder Paul Pogba among six changes and his side struggled to create any clear-cut chances against a determined Denmark.
Deschamps immediately switched his focus towards what he called the “second competition” after the uninspiring contest.
“There’s a second competition that’s going to start, the last 16 is straight elimination,” said the coach, who must now prepare his players to face Messi and Argentina.
“There’s a mountain in front of us now. But we’re there and we’re full of ambition to get to the next stage.”
Australia will go back to the drawing board after they ended bottom of Group C with a solitary point following a 2-0 defeat to Peru, who are also heading home.
Andre Carrillo and Paolo Guerrero, the veteran who was only cleared to play days before the tournament after having a ban for taking cocaine lifted, scored in Sochi.
Tim Cahill, the 38-year-old Australian midfielder, came on as a substitute for his first appearance in his fourth World Cup but was unable to influence the outcome and the Socceroos will have to look to the future with talents such as 19-year-old Iranian-born Daniel Arzani.
Follow the World Cup with The Phuket News
Keep up to date with all the FIFA World Cup results and group standings by following The Phuket News by clicking here.
You can also get a free printable copy of The Phuket News World Cup wallchart via the link.
Best of luck for your home nation!