Bruno Alves scored the winner in the third minute of stoppage time as Portugal beat Mexico 1-0 in Massachusetts.
It was the final warm-up game ahead of the World Cup for both sides, and it looked like each manager would settle for a draw until the closing stages.
Vieirinha had the best of the early opportunities for Portugal, but he was unable to beat Jose Corona with a curled effort after collecting the ball in space inside the box.
Portugal applied most of the pressure in the first half, with another chance being wasted when Eder headed wide from close range just after the half-hour mark.
Mexico fought back impressively in the second half, but they were guilty of not taking advantage as Hector Herrera and Alan Pulido both saw good chances saved by Eduardo.
The match was decided with only seconds remaining when Alves lost his marker inside the box to power home a header from Joao Moutinho's inch-perfect free kick.