The 2016 champions were pushed all the way by Jaime Lozano's side in Kashima but ultimately got the job done on penalties, successfully converting all four of their attempts to reach the final where they will face either Spain or Japan.
Guilherme Arana spurned the best chance of the first half in the 13th minute when he was denied by Guillermo Ochoa with just the goalkeeper in his way.
An even better opportunity looked set to fall Brazil's way soon after as Douglas Luiz was sent tumbling in the box, but the initial penalty award was overturned following a VAR review, with the Aston Villa midfield shown to have exaggerated contact with Jose Esquivel.
The second half was far tetchier, however, with opportunities a rare commodity at either end. The best Brazil could muster until the latter stages was a feeble Antony effort that caused Ochoa no concerns.
Ochoa was beaten in the 82nd minute but the post came to his rescue, with Richarlison's header coming off the inside of the upright but refusing to cross the line.
That saw the match go to extra time and rarely did either side look likely to make the breakthrough, with penalties long appearing a formality.
Eduardo Aguirre missed Mexico's first kick in the shoot-out after Dani Alves had converted, giving El Tri an uphill battle right from the start, and Johan Vasquez did no better with their second as he smashed against the post.
Charly Rodriguez at least got Mexico on the board, but Reinier followed the example set by Gabriel Martinelli and Bruno Guimaraes before him to slot home the decisive kick.
Reigning Olympic champions Brazil eventually toppled Germany 4-2 in the Group D opener in Yokohama, a rematch of the final from the 2016 Games in Rio that went to a penalty shoot-out.
Brazil were pegged back to 3-2 on this occasion before Paulinho's stoppage-time strike ended 10-man Germany's hopes of snatching a draw.
Richarlison made a seventh-minute breakthrough when Germany defender Amos Pieper slipped to allow the Everton striker a clear run on goal. Although his first shot was pushed out by Florian Mueller, Richarlison lashed in the rebound on the half-volley.
A close-range header after 22 minutes made it 2-0 and Richarlison sealed his treble with a shot into the right corner that took a slight deflection off Pieper.
Matheus Cunha missed a penalty for Brazil in first-half stoppage time before clumsy goalkeeping from Santos allowed Germany to get on the scoresheet after the break, Nadiem Amiri's tame volley creeping in.
Germany's Maximilian Arnold was dismissed after a soft second booking for a clash with Dani Alves, but another goal arrived when Ragnar Ache headed home in the 83rd minute, only for Paulinho's clinical breakaway finish, high into the top right corner, to make sure of the points.
Australia enjoyed a banner day as goals from Lachlan Wales and Marco Tilio floored a youthful Argentina side, who had midfielder Francisco Ortega sent off shortly before half-time.
Wales tucked in a low cross from Joel King to give the Olyroos a 14th-minute lead, and Ortega was dismissed for two bookable offences in quick succession to leave Argentina in trouble.
Tilio sealed a 2-0 win with a thumping left-footed strike into the right corner from 20 yards after 80 minutes as Argentina were caught on the break.
France were beaten 4-1 by Mexico, with substitutes Uriel Antuna and Eduardo Aguirre putting the finishing touches to the impressive win with late goals. Andre-Pierre Gignac, who plays his club football in Liga MX, got France's consolation with a second-half penalty.
Burnley striker Chris Wood scored as New Zealand earned a 1-0 win over South Korea, and Milan midfielder Franck Kessie netted in Ivory Coast's 2-1 victory against Saudi Arabia.
Spain were held 0-0 by Egypt, while hosts Japan edged South Africa 1-0 and Romania beat Honduras by the same scoreline.