Marcos Rojo scored a fine late volley to send Argentina through to the last 16 of the 2018 World Cup with a dramatic victory over Nigeria in St Petersburg.
A lacklustre Argentina were on the verge of an embarrassing exit, before Manchester United defender Rojo surged into the area to place Gabriel Mercado's cross into the bottom corner.
Lionel Messi, who had scored a brilliant opener, jumped on Rojo's back as he sprinted away in delirious celebration, joined by the entire Argentina bench in the corner.
It was a result they scarcely deserved after a poor second-half showing, epitomised by the Javier Mascherano error that allowed Victor Moses to equalise with a penalty.
But once their ragged defence had held on until the final whistle, the Argentina players embraced each other in the centre of the pitch, waving to their vociferous fans, a disjointed side united for now.
They will face Group C winners France in the last 16 in Kazan on Saturday, while Group D winners Croatia, who secured top spot by beating Iceland 2-1, play Denmark.
Given Messi will be 35 during the next World Cup in Qatar in 2022, victory here has at least staved off a miserable end to what could well be his last chance to win the tournament.
The Barcelona striker, whose hint of a smile during the pre-match anthems was a stark contrast to his pained expression prior to the 3-0 defeat by Croatia, produced a superb first-half performance.
His opening goal displayed all his talent and composure. With Ever Banega looking to go over the top from deep, Messi cut sharply right and surged in behind the defence, with the Sevilla midfielder picking him out with a terrific pass.
Messi's first touch to cushion the ball on his left thigh was sublime, the second off his left boot to draw it away from Kenneth Omeruo exquisite, the finish into the far corner with his right emphatic.
Elsewhere he was efficient, threatening to create openings with every quick touch, and could have had a second but for Nigeria keeper Francis Uzoho's tremendous save to tip a free-kick onto the post.
With Argentina's players reportedly at odds with boss Jorge Sampaoli, it was perhaps telling that Messi delivered a second team talk to his side in the tunnel just before coming out for the second half.
His words failed to inspire them, with Messi increasingly isolated, but he had at least given his team-mates the foundation to salvage their World Cup.
It is still hard to see Argentina progressing into the latter stages of this tournament without significant improvement, even if Messi goes on to put in performances for the ages.
This was the oldest starting side in the country's hugely successful World Cup history - with an average age of 30 years and 189 days - but it is a far from settled one.
Sampaoli made five changes from the Croatia defeat, including an international debut for 31-year-old keeper Franco Armani after Willy Caballero's blunder.
Some of those changes, like starting Banega, were overdue, but the decision to drop Sergio Aguero and then wait until two other substitutions had been made and 80 minutes had passed before introducing him was bizarre.
If Sampaoli has lost control of the dressing room, Mascherano is supposedly his side's real leader. But the former Barcelona and Liverpool defensive midfielder, who now plays for Chinese club Hebei China Fortune, looks shorn of his former talents, failing to offer protection to a shaky defence.
While not the most blatant example of holding, his grabbing of Leon Balogun in the box from a corner was naive and rightly penalised. Is there any way he can rally his team-mates for the challenge of France?
"It is very hard to see how Argentina can stand up to the French - if they are going to mount any challenge, it will have to be like it was four years ago when they played on individual talent," said BBC Sport's South American football expert Tim Vickery.
"France will not be too concerned about playing Argentina."
Argentina finished second to Croatia, who won all three games in Group D
Just as in their victory over Iceland, Nigeria started cautiously, defending deep, before blitzing the opposition defence at the start of the second half.
Ahmed Musa finally started to test out the Argentina defenders with his pace, leaving them diving into tackles, and he was joined by Odion Ighalo, who replaced the ineffective Kelechi Iheanacho at the interval.
Nigeria induced panic, leading to Moses' penalty, which the Chelsea wing-back converted easily, sending Armani the wrong way as he slotted down the right-hand side.
But the Super Eagles could not keep their composure when close to a second goal, with Ighalo sending a weak shot straight at Armani and also slicing wide when a deflected Musa cross dropped into his path.
After that miss, the former Watford striker made a desperate appeal for a penalty, with referee Cuneyt Cakir consulting VAR but needing only one replay to dismiss the claim, Rojo having headed the ball into his arm.
Wilfred Ndidi also hit a powerful drive just over the bar but Nigeria ultimately could not take advantage of their rattled opponents.
He may have faded after the break, but Argentina's talisman was superb in the first half, scoring a wonderful opener
Argentina captain Lionel Messi: "We were confident we would win this game. It's wonderful to have won it this way - it is a well-deserved joy.
"I thank all the people who are here, for all their sacrifice, and all those who are in Argentina who were always with us. The shirt of the national team is above all."
Argentina centre-back Marcos Rojo: "We needed it, now the World Cup begins for us.
"Lionel Messi had told the guys he was going to score a goal more than ever. The goal is for my family and for this group that deserves it. Let's go Argentina!"
Nigeria captain John Obi Mikel: "We did everything we could. In the second half we pushed and pushed. It just wasn't to be. It's a young team and in four years most of them will be ready for this tournament.
"I'm very proud of the boys and what we have achieved. I think we have done really well. We have to keep going."