Neymar scored one goal and played a key role in the second as Brazil edged out Mexico in Samara to reach the World Cup quarter-finals for a seventh consecutive time.
Brazil did not have it all their own way, especially in an opening period dominated by Mexico, but the five-time winners grew into what became a controlled performance.
It means Mexico are once again eliminated at the last-16 stage – as they have been at every World Cup since 1994.
They did have plenty of chances early on, and it was only after a largely frustrating first half for Brazil that Neymar started the move to put his side ahead.
His run across goal and clever backheel won Willian space, and the Chelsea midfielder only needed two touches to drive into box and lay the ball across for the world’s most expensive player to slide home.
It was Brazil’s 227th goal at the World Cup, meaning they overtake Germany as the all-time top scorers.
In the match’s closing stages they rallied once more, but Brazil defended stoically before doubling their lead on the break through a Roberto Firmino tap-in after Neymar’s effort was diverted by the toe of Mexico goalkeeper Guillermo Ochoa.
Brazil will face Belgium in their last-eight tie in Kazan on Friday.
But they will be without Real Madrid midfielder Casemiro, who will be suspended after being shown his second yellow card of the tournament.
‘Embarrassing from Neymar’
Given his contribution, Neymar should have garnered only positive headlines, but he was the centre of attention for the wrong reasons too after overreacting to a challenge from Miguel Layun in the closing stages.
The Mexico full-back appeared to press his studs against Neymar’s ankle as he retrieved the ball from between the Brazilian’s legs.
There is a national obsession in Mexico that centres on a failure to go beyond four games at a World Cup, stretching back 32 years.
Only once have they done so – at the 1986 tournament they hosted, when they beat Bulgaria in the last 16 before falling to West Germany.
It remains the only World Cup knockout-stage victory in Mexico’s history.
Rafael Marquez, 39, may well remember watching the match. He captained the side against Brazil in Samara, on his first start at a joint record fifth World Cup, before being withdrawn at half-time.
This year will feel like another missed opportunity.
They started the tournament brilliantly with a 1-0 win over Germany, then beat South Korea 2-1, before a 3-0 defeat by Sweden set up a knockout tie with Brazil, a team they have now never scored against in five World Cup meetings.