Portugal had led 2-1 after Ronaldo and Helder Postiga had overturned Antonio Valencia's second minute strike.
But an own-goal from Joao Pereira and a Felipe Caicedo effort sealed a surprise win for the South Americans.
Leo Messi failed to score as Argentina claimed a 3-2 win over Sweden in Stockholm.
An own-goal by Mikael Lustig gave Argentina the lead before Jonas Olsson equalized in the 18th minute.
Manchester City striker Sergio Aguero restored his side's lead 60 seconds later with Gonazlo Higuain adding a third soon after.
Rasmus Elm's 90th minute strike proved a mere consolation for the home side.
Elsewhere, Belgium defeated Slovakia 2-1, Russia won 2-0 in Iceland, Croatia defeated South Korea 4-0 and Romania overcame Australia 3-2.