Cristiano Ronaldo's 80th-minute goal secured Portugal a 2-1 win over Ghana in Brasilia, but the result ultimately eliminated both sides.