European champions Portugal have earned a third-place finish at the 2017 Confederations Cup after recovering from a goal down to beat Mexico 2-1 after extra time.
The Selecao were heading for defeat until Pepe popped up in second-half stoppage time to force a further 30 minutes, during which Adrien Silva netted from the spot to earn the win for his side.
Silva had earlier fluffed his lines from 12 yards, which looked to be costly after Neto scored an own goal to put Mexico ahead, but it was to be Portugal's day in a match that boiled over with the sendings-off of two players at the end.
Portugal, without star man Cristiano Ronaldo this afternoon, created the first opening of the match as Gelson Martins got in behind and pulled the ball back for Nani, who was unable to make the desired contact.
Silva won the penalty that he would go on to see saved by Guillermo Ochoa, being brought down by Rafael Marquez inside the box and being given the decision following a VAR review.
Rui Patricio was required to save his side soon after when the ball bounced around inside the box, before Javier Hernandez had a well-struck shot kept out from 12 yards.
Chances came and went for Oribe Peralta and Hernandez either side of half time, the latter again being thwarted by Patricio from close range.
Moments after Martins failed to find a way through with his volley, Mexico were ahead through a Neto own goal - the keeper seeing the ball bounce off him and over the line following a dangerous cross from Hernandez.
Pizzi could have levelled up on the hour but failed to find the net with his first-time effort, while Martins was brilliantly denied by Ochoa from a header two minutes later.
The game was becoming stretched and there was a good chance for Hernandez to seal it, only to be denied by Patricio, allowing Pepe to dramatically equalise in the 91st minute at the end of a Ricardo Quaresma delivery.
The winning goal arrived 15 minutes into extra time, as Silva this time converted his pen after the ball popped up and hit Miguel Layun on the arm.
Nelson Semedo and Raul Jimenez were both shown second yellow cards in quick succession late in the match, with Portugal doing enough to maintain their unbeaten record against Mexico to finish third.