Neymar was criticised for his early performances in Russia as he eased his way back to fitness after a broken foot bone, but he carved open a tough Mexican defence without quite reaching his dazzling best.
After a goalless first half on a hot afternoon in Samara, the world's most expensive player tapped in from the impressive Willian's cross for his second goal of the tournament on 51 minutes.
As Brazil pressed their advantage, Neymar set up Firmino for another close-range finish that sealed the victory.
In between, he writhed in agony on the turf after a Mexican opponent appeared to stand on his ankle, but the referee ruled there had been no foul and Neymar was soon on his feet.
Mexico threatened at times but their World Cup challenge was ended at the first knockout stage for the seventh consecutive tournament.
Neymar said Mexico had made Brazil work hard: “We have to learn to suffer and we did suffer, it was a tough match. We knew they were a high-quality opponent.”
Brazil will face the winners of the match later Monday between highly fancied Belgium and a Japan side dreaming of reaching the quarter-finals for the first time in their history after scraping through their group thanks to their fair-play record.
Belgium are bristling with talent in the shape of Eden Hazard and Romelu Lukaku, but this World Cup has already shown that nothing can be taken for granted after a series of big names crashed out.
Russian fans celebrated long into the night after they stunned 2010 winers Spain on penalties in an electric atmosphere at Moscow's Luzhniki Stadium on Sunday.
Veteran goalkeeper Igor Akinfeev was the hero for the hosts, saving two spot-kicks.
The win sparked an outpouring of joy on the streets of the capital, with disbelieving locals cheering, waving flags, blowing horns and yelling “Russ-i-a!” Russia, ranked a lowly 70th in the world, will play Croatia in the last eight after similar drama in Nizhny Novgorod, where Luka Modric saw his spot-kick saved late in extra time before they held their nerve to defeat Denmark in the penalty shootout.
Spain had been considered among the favourites but their preparations were wrecked when coach Julen Lopetegui was sensationally sacked on the eve of the tournament.
“The KO in the last 16 is another dark chapter in our history,” said Spanish sports daily Marca, adding that it was “incredible naivety” to think Lopetegui's abrupt sacking would not affect the team.
Spain join 2014 winners Germany, Argentina and European champions Portugal in exiting the competition, leaving just four former World Cup winners in the tournament.
Cristiano Ronaldo and Lionel Messi, who have dominated the game for the past decade, have gone home, their hopes of ever winning the World Cup probably over.
Roberto Martinez's dangerous Belgian side have lived up to their billing so far, winning all three group games. A host of key players including Hazard, Lukaku and Kevin De Bruyne will be fresh after being rested in the 1-0 victory against England.
However, Adnan Januzaj, who scored the winner in that match, suffered a knock to his knee in training.
This is probably the best chance for Belgium's so-called golden generation to win a major trophy after they were eliminated in the last eight at the 2014 World Cup and Euro 2016.
“This is our time to shine, definitely. We have top players and we play as a group, especially after the win over England,” Chelsea star Hazard said.
“It's in our hands. We need to give everything and see what happens.” Japan reached this stage in controversial manner, by virtue of collecting fewer yellow cards in the group phase than Senegal. They have never won a knockout-round game at the competition.
“Maybe Belgium feel the tournament is starting after their three wins, but I'd like to feel we are on a par with them. We have played to our best, but the players have something more to offer,” said Japan coach Akira Nishino.