The substitute Firmino added the clincher in the 88th minute on a carbon copy goal: this time it was Neymar who burst in on the left and Firmino who slid into the goalmouth to turn the ball home.
Brazil will face Belgium or Japan - who meet in Rostov-on-Don in the day's second match - in their last-eight tie in Kazan on Friday.
Twelve minutes before half-time and Gabriel Jesus worked himself some space in the area, but shot too close to Ochoa, before Jesus Gallardo was on hand to clear the Manchester City forward's follow-up shot off the line.
He darted across the edge of the area before a flawless backheel released Willian, whose low cross fizzed into the danger area where Neymar slid in to turn the ball home.
One person dies after blast at Zimbabwe president's rally; state radio
Several security personnel were also hurt, the state-owned Herald newspaper said. State broadcaster ZBC described the blast as "an assassination attempt".
And their positive approach was rewarded in the 51st minute as Neymar and Willian combined to devastating effect.
Paulinho nearly doubled the lead before the hour, but his shot inside the box was kept out by the excellent Ochoa, who then had to tip Willian's fizzing drive over the bar.
Brazil's World Cup campaign thus far has seen them improving in each match they have played so far.
After Mexico lost an errant pass in the midfield in the 89th minute, Neymar collected the ball and began running Brazil up the field with a numbers advantage. Marquez's inclusion meant Miguel Layun dropped to the bench and the responsibility rested with Hirving Lozano and Carlos Vela to support lone striker Javier Hernandez.
After their slow start it was ultimately no more than the Selecao deserved, as their bid for a sixth world title marches on.