The game looked set for a goalless draw when Bruno Alves soared to plant a powerful header past goalkeeper Guillermo Ochoa in the 93rd minute from a cross by Joao Moutinho. (JPN/Agencies)
Portugal, missing captain Cristiano Ronaldo who is suffering from tendinosis and a thigh injury, also had to thank their stopper Eduardo who gave an inspired performance.
Mexico dominated the second half but Eduardo kept them out with fine saves from Hector Herrera, twice, and Alan Pulido leaving the door open for Bruno Alves to grab the late winner.
Ronaldo relishes Portugal's underdog status
Cristiano Ronaldo finally ended Lionel Messi's four-year reign as soccer's best player in 2013 and a starring role for Portugal at the World Cup finals would cap another stellar season for the astonishing forward.
The 29-year-old from humble roots on the island of Madeira is now a marketing phenomenon with almost 80 million followers on Facebook.
He scooped his second Ballon d'Or award in January despite not winning any silverware with Real Madrid the previous season but did score in last month's Champions League final to help Real secure their record-extending 10th European crown.
While he inspires a mixture of love and loathing among fans of all stripes, few would dispute he is one of the greatest goal-scorers to have played the game.
Since joining Real from Manchester United in 2009 for what was then a world record fee of 94 million euros ($128 million), Ronaldo has shown incredible consistency and Argentina's Messi is the only player who has bettered his goals tally in the past five seasons.
The sight of Ronaldo sprinting forward on another devastating Real counter-attack or smashing in a free-kick has become as familiar as that of Messi weaving his way towards goal and sliding the ball into the net.
Ronaldo is more like a racehorse, galloping past defenders and firing thunderbolt shots from all directions. He became Portugal's top goal-scorer when two goals in a 5-1 friendly defeat of Cameroon in March took his tally to 49 in 110 games.
Despite the deluge of goals, he has sometimes been accused of going missing in the big games and he failed to score against Spain in the round of 16 at the World Cup finals in 2010 or in the semi-finals of Euro 2012.
However, after an erratic Portuguese qualifying campaign he single-handedly secured their berth at the finals in Brazil when he netted all four goals over the two legs of their 4-2 aggregate success against Sweden in November's playoff.
Portugal have been drawn with Germany, Ghana and United States in Group G in Brazil and Ronaldo has said he will relish not playing under the same pressure he feels at Real.
Portugal's best result at a World Cup was third on their first appearance in 1966. "We are not favourites which is good for us, it takes out a lot of pressure," Ronaldo said in March.
"We know that Spain, Brazil, Germany, Argentina, they are favourites, which is fantastic for us. But I am quite confident we can do it. We have a difficult group, in my opinion, and we are going to go step by step, game by game,” he said.
"The first game will be very, very difficult against Germany, but I believe we are going to have a fantastic World Cup, and without pressure, which is amazing," he added.
The game looked set for a goalless draw when Bruno Alves soared to plant a powerful header past goalkeeper Guillermo Ochoa in the 93rd minute from a cross by Joao Moutinho.