The match went on to extra-time and Portugal's Adrien Silva gave them the victor in the 104th minute.
Veteran Rafael Marquez was punished for a poor challenge by a VAR referral but Andre Silva, who was handed the responsibility with Cristiano Ronaldo having been allowed to travel home to be with his new twins, saw his effort brilliantly saved by Guillermo Ochoa.
Their worries were then compounded when Luis Neto's own goal in the 54th minute put Mexico ahead.
Saints Place DT Nick Fairley on Reserve/Non-Football Illness List
New Orleans Saints announced Monday that DT Nick Fairley has been placed on the team's reserve/non-football illness (NFI) list. With Fairley out, the Saints will lean on Sheldon Rankins , David Onyemata and Tyeler Davison as their top interior defenders.
Both teams ended the match with 10 players after Nelsinho and Raul Jimenez were both given their marching orders.
Hernandez's cross from the byline floated beyond Carlos Vela and Patricio, with Zenit St. Petersburg centre-back Neto unwittingly turning the ball home.
But Ochoa was beaten in the first minute of injury time as Pepe lunged to get on the end of Ricardo Quaresma's curling right-wing cross to force extra time.
Adrien Silva scored an extra-time penalty as Portugal recovered from a goal down in the tension-soaked match.