Neymar scored the first goal of the Brazil-Mexico match in the 50th minute.
Brazil's midfielder Roberto Firmino scored the second goal in the 88th minute, firing a low shot that was almost saved by Ochoa.
The 26-year-old Paris Saint-Germain striker, who broke out in tears after scoring his first goal of the tournament in Brazil's 2-0 Costa Rica win, was all smiles after he tapped in Willian's powerful cross in the 51st minute.
Forward Neymar was named the man of the match as Brazil defeated Mexico in its round of 16 match at Samara Arena.
The Mexican national team has been knocked out from the round of 16 every World Cup since 1994.
In the 71st minute Neymar rolled around on the floor after Layun lightly touched his ankle when retrieving the ball.
Five substitutions have so far been made.
During the second half, Casemiro brought down Lozano and Herrera pulled back Willian; both footballers received yellow cards.
Alvarez had taken out Neymar 30 yards from the goal and received a yellow card.
Filipe Luis later wiped out Lozano on a Mexico counter and was penalized accordingly.
Brazil, who last failed to make it to the quarterfinals in 1990, will play either Belgium or Japan in the last eight in Kazan.
The round of 16 match between Brazil and Mexico had taken place in the Russian city of Samara.
The Brazilian national football team has finished Group E after a very poor start. After drawing 1-1 against Switzerland in their first game and later claiming a 2-0 win over Costa Rica, they beat Serbia 2-0 and have now secured a spot in the quarterfinals.
The Mexican squad has become popular with their crushing 1-0 victory over Germany followed by a stunning 3-0 loss to Sweden.