The Super Eagles were heading through to the last 16 at Argentina's expense with four minutes to go of the final Group D game, but Rojo's sensational low volley saved Jorge Sampaoli's men and set up a showdown with France in the next round.
But when Javier Mascherano dragged down Leon Balogun in the box shortly after the restart, Victor Moses stepped up to roll Nigeria level and within touching distance of progressing.
Sampaoli sent on attackers Cristian Pavon, Maximiliano Meza and Sergio Aguero, but it was defender Rojo who came up with a quite brilliant winner.
The right-wing cross from another defender, Gabriel Mercado, was perfectly placed for Rojo to arrive late and slam home an improbable, unstoppable finish that extends Argentina's stay at the World Cup.
After scoring a brace in Nigeria's win over Iceland, Ahmed Musa sought to test debutant goalkeeper Franco Armani early, but narrowly cleared the crossbar with his ambitious effort.
Argentina made a nervy start before taking the lead in the 14th minute thanks to some Messi magic.
Ever Banega was making his first World Cup start and the Sevilla star's ball over the top was perfect, Messi controlling the ball on his thigh and left boot in one fluid movement before lashing an unstoppable right-footed drive past Francis Uzoho.
The Nigeria goalkeeper was rapidly off his line to deny Gonzalo Higuain as Argentina sought a second and the teenager was brilliant again as Messi took aim in the 34th minute.
Leon Balogun brought Angel Di Maria down 25 yards from goal, but, while Messi beat the wall with his free-kick, Uzoho got the slightest of touches to tip the shot on to his left-hand post.
Oghenekaro Etebo narrowly missed with a long-range free-kick before Rojo came up with one of the most dramatic moments of modern World Cup history in the 86th minute.
2 - Marcos Rojo has scored both of his World Cup goals against Nigeria. Bogeyman. pic.twitter.com/XwwJwEwuAg— OptaJohan (@OptaJohan) June 26, 2018
Mercado raided down the right and bent a delicious cross into the penalty area, Rojo timing his run perfectly to tuck home a low right-footed volley that gave Uzoho no chance.
Argentina's reward will be a last-16 clash against Group C winners France, with Nigeria - the youngest squad at the World Cup - left heartbroken by Rojo's stunning strike.
Key Opta stats:
- Argentina have qualified from the World Cup group stages for the fourth consecutive tournament (2006, 2010, 2014 and 2018).
- Nigeria have now been eliminated in the group stages in three of their last four World Cup campaigns (2002, 2010 and 2018).
- Argentina are unbeaten in their last 40 World Cup games when opening the scoring (W35 D5), since a 1-3 defeat against Germany in 1958.
- Lionel Messi's first-half goal for Argentina ended a run of 662 minutes without a goal in the World Cup – his last goal came in June 2014, also against Nigeria.
- Messi (2006, 2014 and 2018) is the third Argentina player to have scored in three different World Cup tournaments, alongside Diego Maradona (1982, 1986 and 1994) and Gabriel Batistuta (1994, 1998 and 2002).