Messi, who has been regularly criticised for his performance in international matches, scored his fourth goal of the tournament, making him the joint top scorer along with Brazil star Neymar.
Messi opened the scoring in the third minute smashing the ball in from close range. Nigeria shocked their opponents a minute later for the equaliser from Ahmed Musa.
Messi’s 45+1 minute freekick put Argentina ahead for the second time but they were once again pegged back by Musa two minutes into the second half.
Defender Marcos Rojo scored the winner in the 50th minute to make it three wins out of three for Argentina.
Argentina had already qualified for the last-16 and with Iran losing 1-3 to Bosnia-Herzegovina, Nigeria too reached the knockout stage.
The South American giants topped Group F with nine points while Nigeria were second with four points.
Bosnia had three points while Iran finished without a win and just a single point.
It was a scintillating performance from Messi and Real Madrid winger Angel di Maria and caused many problems for the Nigerian defence.
It was the first real performance from a team regarded as the favourites by many to lift the trophy after two flat showings in their opening two matches.
It wasn’t all plain sailing for Argentina, though, and their defensive performance would be a cause for concern for coach Alejandro Sabella.
It was a lazy performance from the Argentine back four and too many times did they let Nigeria attackers venture into the box.
Argentina will have to shore up their defensive skills if they are to have a chance of winning their third World Cup.
Argentina and Nigeria had met six times before the Wednesday match, and Argentina won four of them, including all three meetings on the World Cup stage.
The Argentine fans, who created a deafening sound in the Estadio Beira-Rio, didn’t have to wait long for the first goal.
In the third minute, Di Maria struck the post after a one-on-one encounter with Nigerian goalkeeper Enyeama.
Messi was there to catch the rebound and the Barcelona star smashed the half volley into the top netting.
Nigeria, however, hit back instantly and tied the score within a minute.
Ahmed Musa got the ball from Babatunde, cut into the Argentina penalty area and curled in the ball into the net.
Only twice before the match there had been two goals in the first four minutes of a World Cup match — Austria-Czechoslovakia (3rd min and 4th min) in 1954 and Soviet Union-Hungary (2nd min and 4th min) in 1986.
The Nigeria goal opened the match even further as both sides attacked with great vigour.
While Argentina held the lion share of the possession and constantly made inroads into the opposition box, Nigeria played on counter.
The South Americans suffered a setback with Manchester City striker Sergio Aguero being subbed in the 37th minute.
The Argentines kept creating chances after chances but couldn’t find the goal.
It took a Messi free kick in the 45+1 minute to breakthrough Nigeria and give Argentina the lead for the second time in the match.
Musa was again at hand to score the equaliser with a 47th minute strike that silenced the strong Argentine contingent sitting in the stands.
However, they burst into raptures once again just three minutes later as Rojo found space in the box after a corner and kneed the ball in.
The game finally seemed to settle in the final 30 minutes as the pace of the game slowed down.