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.
Just moments earlier, Mexico’s Jesus Gallardo wasted a brilliant chance when he shot wildly over the crossbar, instead of playing in Hirving Lozano.
For much of the second half, Mexico’s bright start was just a memory, but Carlos Vela forced a save from Brazil goalkeeper Alisson with his side’s first shot on target not long after going behind.
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.
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.
Neymar, who was sitting down, writhed around in apparent agony before getting up to carry on without any issue.
“I’m embarrassed for Neymar,” said former England striker Dion Dublin on BBC.
“He is one of the world’s greatest players, but when he rolls about on the floor, I just don’t get it. Come on young man, you’re better than that, get on with the game.”
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.
Belgium completed a remarkable revival as they came from the World Cup abyss and beat Japan to reach the quarter-finals.
Roberto Martinez’s side were trailing 2-0 when he brought on Marouane Fellaini and Nacer Chadli in the 65th minute, and Fellaini scored the equaliser before Chadli netted a 94th-minute winner.
Japan looked on their way to a famous win in Rostov after Genki Haraguchi ran onto Gaku Shibasaki’s long ball, which Jan Vertonghen should have cut out, to open the scoring.
Takashi Inui’s 25-yard strike made it 2-0 and looked set to take the Asian side to their first ever quarter-finals.
Belgium’s Premier League stars — their golden generation — had put in a disappointing performance and Martinez turned to the oft-ridiculed Fellaini and West Brom winger Chadli in his hour of need.
Their fortunes changed after that as Vertonghen scored a looping header to get them back into the game.
Fellaini then headed in Hazard’s cross to level before Chadli converted Thomas Meunier’s pass to finish off a flowing move and help the Red Devils avoid being the latest victims of a World Cup of shocks.
Belgium become the first team to fight back from two goals down to win a World Cup knockout game since Germany against England in 1970.
Belgium clearly have the players — Hazard, Kevin de Bruyne, Romelu Lukaku and Thibaut Courtois are some of the Premier League’s undoubted stars.
They are now unbeaten in 23 games, but there are always questions about whether they are tactically astute.
Martinez and his players will feel they have gone some way to answering those, and finding a real winning touch, having looked dead and buried after an hour.
Chelsea winger Hazard had hit the post in one their few good chances in the opening 60 minutes.
But they ground their way back into the game – even though the goal to give them hope was a bit of a fluke.
Inui booted the ball up into the air and Vertonghen’s looping header flew over keeper Eiji Kawashima, who should have done better.
At 20 yards, it is the longest headed goal since those stats were first recorded in 1966.
Then the substitutes came to the fore. Fellaini, who signed a new Manchester United deal last week, powered in Hazard’s centre to level the scores after 74 minutes.
And the winner was a real team effort. Goalkeeper Courtois rolled the ball to De Bruyne, who had been quiet for 90 minutes but exploded into life when his country needed him.
The Manchester City playmaker carried the ball 60 yards before feeding Meunier, his cross was stepped over by Lukaku, and Chadli was on hand to steer it home.
Lukaku had scored 17 goals in his previous 11 Belgium games but his decision to not shoot on this occasion might prove more crucial than any of those.