Messi’s two goals were twice cancelled out by Nigeria’s Ahmed Musa but Marcos Rojo’s second-half finish made sure Argentina took all three points.
Despite their defeat, Nigeria also progressed to the last 16 as Iran were beaten 3-1 by Bosnia-Herzegovina – meaning the Super Eagles go through as runners-up.
Messi’s double means he is now joint top-scorer with Neymar on four goals and while the number 10 was substituted and spared the final half an hour of the game, his emphatic form means Argentina will go into the competition’s latter stages in high spirits.
“We were better in this game, regardless of the goals we conceded,” Messi said. “We were more threatening today, found the spaces to exploit and had more chances to score. But we still want more. We’re all still chasing a shared dream.”
It took less than three minutes for the South Americans to break the deadlock. Javier Mascherano fired an incisive pass to Angel Di Maria and while the winger’s shot was saved by Vincent Enyeama, the ball cannoned off the near post and into the path of Messi who shot high into the net.
One minute and 20 seconds later, Nigeria were level. Michel Babatunde broke from midfield and played the ball left to Musa who skipped inside Pablo Zabaleta before curling the ball brilliantly past Romero.
Sergio Aguero’s injury-plagued season continued as the Manchester City forward hobbled off in the 37th minute and was replaced by Ezequiel Lavezzi.
Moments before the break Messi was given a second opportunity, slightly closer in, and this time he made no mistake, chipping the ball over the wall and beyond Enyeama to make it 2-1 on the stroke of half-time.
The second period began just as frantically as the first with two more goals in the opening five minutes.
Nigeria drew level for the second time in the match and again it was Musa with the strike, as he ghosted through the Argentina defence before slotting past Romero to make it 2-2.
Nigeria’s parity was short-lived, however, as the lively Di Maria fizzed a shot from the edge of the area which Enyeama did well to palm behind.
From the resulting corner Argentina found the net as Nigeria’s defence failed to clear and Rojo was left free to turn the ball home from close range.
Nigeria then went close at the other end as Musa again cut inside Zabaleta on to his right foot but this time the Argentina full-back read the move and was able to block the shot.
Ezequiel Garay should have put the result beyond doubt with a header at the back post in the final 10 minutes but it proved inconsequential as both teams advanced.
“It’s an honour and we’re very happy to reach the next round,” Nigeria coach Stephen Keshi.
“I think we lost the game because we showed them too much respect in the first half. After the break we managed to play our game, attacked more, had more possession and were better overall. But Argentina are a great team and Messi’s a great player. He’s blessed and there’s no way you can escape him. Messi’s from Jupiter.”
NIGERIA: Enyeama, Ambrose, Yobo, Omeruo, Oshaniwa, Onazi, Mikel, Babatunde (Uchebo 65), Odemwingie (Nwofor 80), Emenike, Musa.
ARGENTINA: Romero, Zabaleta, Federico Fernandez, Garay, Rojo, Gago, Mascherano, Di Maria, Messi (Alvarez 63), Higuain (Biglia 90), Aguero (Lavezzi 38).
Referee: Nicola Rizzoli (Italy).