Messi broke to set up Angel di Maria to open the scoring before Ronaldo equalised for Portugal, but the Barcelona man won the game with a penalty in the last minute.
Elsewhere, Spain beat Colombia 1-0 thanks to David Silva whilst Karim Benzema helped France beat Brazil by the same score. Germany and Italy drew 1-1 in a repeat of the famous game at the 2006 World Cup, when Italy won 2-0 to progress to the World Cup final.