Brazil, who will have to do without defensive midfielder Casemiro in the quarters after he picked up his second booking, had to wait until the 88th minute to put the match to bed.
At the 51st minute, Brazil would finally break the game open.
The margin became more comfortable with two minutes left when Firmino - just on as a replacement for Coutinho - added the finishing touch after Neymar had led a counter-attack. It turned out to be pure histrionics.
Before setting up the second goal it looked like Neymar's game - or even his World Cup - could be over with 20 minutes to go.
Then, things took a darker turn when Layun appeared to step on Neymar following another altercation on the touchline.
Brazil will face the victor of Belgium-Japan on Friday in the quarterfinals.
For Mexico, the defeat is no doubt a big disappointment for a talented group of players and millions of fans around the country who, after a promising start to the tournament, had dared to dream that El Tri could go farther in Russian Federation 2018 than the team had ever gone before.
Mexico head coach Juan Carlos Osorio was critical of Neymar in his post-match media conference, and Layun believes it is a shame such a talented player allows less favourable aspects to creep into his game.
Neymar's reaction may have had something to do with it as the Brazilian was criticised from all four corners of the world for his actions.
"We know Neymar and he likes to be the protagonist on and off the field".
Brazil kept up the intensity as Neymar weaved through two defenders to curl in from an acute angle, but Ochoa spread out his right arm to punch clear.
TRT World's Jon Brain reports from Mexico's Tijuana with the latest developments on World Cup. "We have to minimise the possibility for the ball to get through to them", Silva said. Speaking on the allegation of going down easily, Neymar said, "It is an attempt to undermine me and my team".
Tite's team progress through to the quarter-finals having registered their third consecutive clean sheet and Selecao will now face the winners of the clash between Belgium and Japan.