|Neymar celebrates after scoring the opening goal.
The PSG forward slid home in the second half and then teed up Roberto Firmino late on as the five-time champions beat an otherwise stubborn Mexico, whose World Cup began with such promise with a victory over champions Germany but ended in familiar fashion in the first knockout round.
It was the seventh World Cup running that Brazil have reached the last eight, where they will now face Belgium or Japan, while Mexico have not made it to that stage since they hosted the tournament in 1986.
Mexico, who enjoyed an enviable recent record against Brazil having won seven of their previous 15 matches against them, were a threat on the counter in the first half but then faded without ever really being put to the sword.
A glaring spotlight had been on Neymar after his opening three performances saw him miss a litany of chances, frequently squander possession and spend far too long on the turf.
Yet he answered a number of questions with a much more positive display and a decisive finish early in the second half from a move that he had started himself, although his propensity for histrionics were again in evidence.
Minutes after the restart Brazil took the lead in exquisite fashion with Neymar starting and ending the move.
He darted across the edge of the area before a perfect backheel released Willian, whose low cross fizzed into the danger area where Neymar slid in to turn the ball home.
It was a choking blow for Mexico, who had been the better side for the opening half an hour, pegging Brazil back and creating several half chances.
Brazil had to wait until the 88th minute to put the match to bed as Neymar was the architect, crossing for Firmino to tap the ball home.
They will have to do without defensive midfielder Casemiro in the quarters, however, after he picked up his second booking.