Nigeria scraped through behind already-qualified Argentina, becoming the first African team to reach the last 16 at this tournament, while Iran's hopes ended in a 3-1 loss to World Cup debutants Bosnia, who enjoyed their first win at the finals.
Messi joined Brazil's Neymar as joint top scorer at the tournament with four goals after his brace against the Super Eagles in Porto Alegre.
Away from the action on the pitch, Luis Suarez's lawyer flew to Rio de Janeiro to present his defence after the Uruguay striker was accused of biting opponent Giorgio Chiellini during the 1-0 win over Italy on Tuesda.
Suarez has twice been banned for biting at club level, in the Netherlands and England, and faces a lengthy suspension if found guilty.
"We're polishing off a defence argument," Alejandro Balbi told local radio in Uruguay, where many people support Suarez and are angry at what they feel is a "manhunt" being orchestrated by media in Europe.
"We don't have any doubts that this has happened because it's Suarez and secondly because Italy was eliminated," added Balbi, who is also a Uruguay FA board member. "There's a lot of pressure from England and Italy."
FIFA said its disciplinary committee would work quickly to investigate the incident, with Uruguay due to play Colombia on Saturday in Rio de Janeiro in the last 16.
Meanwhile, Ghana became embroiled in a row over appearance fees on the eve of their decisive Group G match against Portugal which needed the intervention of President John Mahama.
In Porto Alegre, Argentina's Messi lashed in a rebound after three minutes but Nigeria equalised a minute later with a superb finish by Ahmed Musa. But Messi was not to be outdone and curled in a brilliant 20-metre freekick in first-half stoppage time.
Musa levelled again with a clever finish two minutes after the restart but Argentina, who were assured of qualification before kickoff, got a fortunate third eight minutes later when a corner bounced in off the knee of Marcos Rojo.
Argentina finished top of Group F with a maximum nine points, followed by Nigeria (4), Bosnia (3) and Iran (1).
Bosnia, already eliminated after two losses in their first appearance at a major tournament since independence, went ahead in the 23rd minute through Edin Dzeko.
They doubled their lead just before the hour through Miralem Pjanic's cool finish before Reza Ghoochannejhad pulled a goal back for Iran in the 82nd minute.
Avdija Vrsajevic restored Bosnia's two-goal cushion with a fine strike a minute later.
In later matches on Wednesday, Group E leaders France (6 points) were facing Ecuador (3) in Rio de Janeiro with Switzerland (3) playing Honduras, who have yet to win a point, in steamy Manaus (both 2000 GMT).
The group stage ends on Thursday when Germany and the United States, who have four points each, meet in Recife (1600) where both will qualify with a draw, while Portugal and Ghana, with one point each, clash in Brasilia in the other Group G game.
Algeria (3 points) need a win against Russia (1) in Curitiba (1700) to make sure of qualifying from Group H, although a draw should be enough. South Korea (1) face already-qualified Belgium in Sao Paulo and have only a remote chance of going through.
Portugal's fiery coach Paulo Bento has said he would not resign if his team failed to progress, while Ghana were expecting to receive their appearance fees after the Ghana FA GFA) promised to send the money by plane.
"We wish to assure the general public following President Mahama's intervention, the Black Stars are in high spirits," said the GFA in a statement.