Substitute Adrien Silva converted a 104th-minute penalty for the game-winner after defender Pepe had levelled in stoppage time for Portugal who fell behind from Luis Neto's own goal and had a first spot kick from Andre Silva saved.
Both teams ended the match with 10 players after Nelsinho and Raul Jimenez were both given their marching orders.
Berkshire Hathaway Inc. (BRK.B) Upgraded by Vetr Inc. to "Buy"
Its largest investments are in single-tenant properties such as chain restaurants, veterinary clinics and fitness centers. Stock market analysts and brokers have recently amended their target prices on shares of Berkshire Hathaway (NYSE:BRK-B).
World champion Germany faces Copa America holder Chile later in the final in Saint Petersburg. But despite the big score played the national team of Mexico, it was bright with fire and by and large in no way inferior to formidable opponents, well, the defeat certainly did not deserve.
Hernandez drove to the byline to the left of the area and drilled the ball back across goal and, when Patricio failed to intercept, the ball cannoned off Neto's shin and into the net.
But Ochoa was beaten in the first minute of injury time as Pepe lunged to get on the end of Ricardo Quaresma's curling right-wing cross to force extra time.