The teams played to a 2-2 draw in the group stage at the beginning of the tournament.
Portugal fought back and Pepe netted home a dramatic equaliser in stoppage time to send the match to extra time.
Mexicans in the semi-finals lost the German national team 1: 4, interrupting their series of 7 unbeaten games. European champion Portugal was without captain Cristiano Ronaldo after the Real Madrid star was released from the squad to return home to meet his newborn twins.
Their worries were then compounded when Luis Neto's own goal in the 54th minute put Mexico ahead.
Nani headed over when unmarked in front of goal from the resulting corner as Portugal tried to keep up the early pressure, but it took a fine one-handed save from Rui Patricio to stop Mexico snatching the lead through Hernandez. According to the old tradition, games for the third place are effective, opponents play at their pleasure, trying to finish the tournament with a attractive game. Silva, on as a substitute, then grabbed the victor just before the end of the first period of extra time, burying a penalty after Miguel Layun handled in the box.