Brazil are through to the knockout stages as Group A winners, where they will play Chile after beating the already-eliminated Cameroon 4-1 in Brasilia last night.
Neymar score a brace which included the 100th goal of the finals, while Fred and Fernandinho were also on target for Luiz Felipe Scolari’s side. Joel Matip scored what proved to be a consolation for the Africans.
Mexico left it late in Recife, but comfortably sealed second place in the end with a 3-1 win over Croatia.
Rafael Marquez broke the deadlock with 18 minutes remaining, before further strikes from Andres Guardado and substitute Javier Hernandez set up a last 16 showdown with the Netherlands. Ivan Perisic grabbed a consolation for Niko Kovac’s men who had Ante Rebic sent off in the closing stages.
A draw would have been enough to see the hosts advance, but they ensured that they topped the group with a comprehensive performance.
Neymar opened the scoring on 17 minutes when he coolly side-footed home Luis Gustavo’s cross, but Matip silenced Estadio Nacional nine minutes later when he turned in Allan Nyom’s square ball.
Brazil’s talisman got his second before half-time, driving into the heart of the defence before sending Charles Itandje with a drilled effort from just outside the box.
Fred made it three after the break when he found himself unmarked in the six-yard area, to nod home David Luiz’s ball after some great work from Fernandinho.
The Manchester City player then got on the score sheet himself with six minutes remaining, when he slid home number four after playing a neat one-two with Oscar.
Mexico also needed just a point to progress to the knockout phase, and they were involved in a solid battle to go through with Croatia at Arena Pernambuco until the 72nd minute.
Captain Marquez set a record for skippering his country at the fourth consecutive finals, and he put them in front with a powerful header from Hector Herrera’s corner.
Andres Guardado doubled the lead three minutes later when he found himself in too much space in the area, and side-footed Oribe Peralta’s square ball into the roof of the net.
Hernandez came off the bench and broke his 11-game goal drought when he made it three in the 82nd minute, with the simplest task of helping the ball in from two yards out after Marquez flicked on another corner.
Kovac’s men did manage to get on the score sheet with four minutes to go, as Perisic played a nice one-two with Ivan Rakitic before driving the ball past Guillermo Ochoa – the first goal he has conceded during the tournament.
They could not find any more though and their frustration boiled over when substitute Rebic was sent off for a high foot on Carlos Pena in the closing stages.
Confirmation of the final Group A standings sees Brazil and Mexico both on seven points with the hosts top on goal difference. They will face Chile and the Netherlands respectively, while Croatia are third with three points and Cameroon finish bottom and pointless for the second straight finals.