The visitors took the lead through Antonio Valencia but Cristiano Ronaldo equalised before the break. The home side went 2-1 in front thanks to Helder Postiga, but a glaring own goal and a fantastic strike from Felipe Caicedo saw the South American's turn the game on its head and snatch victory.
An explosive start in Guimaraes saw Portugal create the opening chance of the game after just 45 seconds, but neither Ronaldo nor Helder Postiga could find a way past Maximo Banguera from Luis Nani’s cross.
It took Ecuador less than a minute to capitalise on the host’s profligacy in front of goal as Valencia put la Tri ahead with just two minutes on the clock.
Jefferson Montero powered his way down the left and found plenty of space to loop in a cross that goalkeeper Eduardo badly misjudged, allowing the Manchester United winger to head into an empty net.
The hosts went in search of a quick response and Nani would have provided it but for an excellent last ditch challenge by Frickson Erazo as the tricky winger shaped to fire past Banguera.
A Selecao almost found themselves even further behind just after the 20 minute mark, as Ecuador’s front pairing of Christian Benitez and Felipe Caicedo combined to carve open their opponents defence, Eduardo making amends for his earlier mistake to tip Caicedo’s effort wide.
Portugal found an equaliser through a familiar source as Ronaldo brought his side level midway through the opening period.
The forward latched on to a flick from his Real Madrid team-mate Fabio Coentrao and his expertly timed touch took the ball away from the challenge of Valencia, before he lashed home to celebrate his 101st cap in style.
Benitez then wasted a free kick in a dangerous position and Helder Postiga had a penalty appeal turned down as the sides went into the break all square.
The hosts started the second half much the brighter and Coentrao had an opportunity to score after being neatly set up by Joao Moutinho, but the left back could not find the target from inside the area.
Portugal did manage to take the lead on the hour mark though, when Nani broke into the left-hand side of the box and slid the ball across goal for Postiga to provide the simplest of finishes.
However the celebrations were short-lived as a calamitous moment in defence saw the home side needlessly squander their advantage just seconds later.
Caicedo’s lofted pass behind the defence looked harmless as Joao Pereira raced to the loose ball, but the defender’s back pass rolled agonisingly past his keeper and over the line to instantly restore parity.
The substitution of Ronaldo saw the visitors grow in confidence and they took the lead for the second time on the night when their front pair combined once more, this time to provide a moment of magic.
With the host’s main threat withdrawn, Valencia was given more freedom to move forward and his cross-field ball was chested by Benitez into the path of Caicedo, who unleashed a ferocious effort that bounced into the turf and crashed into the back of the net beyond Eduardo.
A stunned Portugal side could not draw themselves level, rattling the crossbar with their only effort of note, as a host of substitutions stalled the host’s fluidity and saw Ecuador see out a famous victory with some ease.