Cristiano Ronaldo's first goal of the World Cup earned Portugal a 2-1 win over Ghana but couldn't prevent his team being eliminated from the tournament along with the Africans on Thursday.
Portugal finished level on four points with second-place United States in Group G but with an inferior goal difference. Germany topped the group after beating the U.S. 1-0 in Recife.
Ronaldo slammed home the winner at Estadio Nacional with his left foot in the 80th minute to break his drought in Brazil and give Portugal its first win. He barely celebrated, though, with the goal coming too late to help Portugal qualify at the expense of the Americans.
"We created many opportunities but we could not finish them," Ronaldo said. "We knew we had to score three goals and were depending on the result of the Germany game and we couldn't do that.
"We deserved more, but that's football. We are leaving with our heads held high."
Ghana captain Asamaoh Gyan's 57th-minute header canceled out an own goal scored by teammate John Boye in the 31st.
It was a bittersweet ending to the World Cup for Ronaldo, who has been nursing a left leg injury and seen the likes of Brazil star Neymar and Argentina captain Lionel Messi upstage him with four goals apiece.
The world player of the year earned the man-of-the-match award after a display that could easily have yielded three or four goals. Ronaldo struck the bar in the first half and had two great chances in injury time, but glanced a close-range finish over the bar and then shot straight at Fatawu Dauda when one on one with the goalkeeper.
It was too little, too late from Ronaldo, who was downbeat as he trudged off the pitch after the final whistle.
The result brought to an end a typically eventful few weeks in Brazil for the Ghanaians, who were part of thrilling games against the United States and Germany before their campaign ended in turmoil on and off the pitch.
Their players took to the field in the Brazilian capital amid a dispute with the country's football federation over alleged unpaid World Cup bonuses. Adding to the chaos, two of the team's star players — Sulley Muntari and Kevin-Prince Boateng — were booted out of the squad hours before Thursday's kickoff for disciplinary reasons.
"I don't think it had an impact on the game," said Ghana coach Kwesi Appiah, who confirmed that his players received their appearance-fee payments before kickoff as requested.
"We had our chances but couldn't take them."
It was perhaps no surprise that Ghana delivered its most subdued display of the tournament, ensuring the team finished bottom of the group and resulting in Ronaldo getting time and space to enjoy his most lively performance in Brazil.
He could have had a hat trick by the time he finally found the net.
An over-hit cross in the fifth minute flew over Dauda and slammed against the bar before the Real Madrid superstar squandered a gilt-edged chance, heading straight at the keeper from six yards (meters) out.
After having two stinging shots saved, he was bailed out by Boye, who sliced Miguel Veloso's cross into the top corner of his own net to give the Portuguese a halftime lead they just about deserved.
Gyan could hardly miss with a header after Kwadwo Asamaoh's delicious cross with the outside of his left foot, making it 1-1. With Germany having just taken the lead in Recife, Ghana was only a goal away from progressing at that stage.
However, Ronaldo had the final say, making no mistake from eight yards (meters) out after Dauda had parried the ball high into the air.