RECIFE/BRASILIA: Thomas Mueller scored his fourth goal of the World Cup on Thursday as Germany defeated the United States 1-0 to win Group G ahead of the Americans, who also advanced to the knockout stage of the World Cup despite losing.
With two wins and a draw, Germany topped the group with seven points, while the US progressed with four.
Portugal beat Ghana 2-1 but both were eliminated. Portugal also finished with four points but the US had a better goal difference.
Mueller scored in the 55th minute with a side-footed shot from the edge of the area as tropical downpours drenched the Arena Pernambuco. Both teams knew before kickoff that a draw would see them through, but neither held back.
The game pitted Germany coach Joachim Loew against his good friend and predecessor Juergen Klinsmann, now in charge of the US team.
The two coaches smiled as they shook hands and patted each other on the shoulder after the match. Germany's goal came after a corner by Mesut Ozil.
US goalkeeper Tim Howard did well to punch out a header by Per Mertesacker but the ball fell kindly to Mueller, who pounced on the rebound and rifled a shot inside the far post from the edge of the penalty area.
Mueller played despite needing five stiches to close a cut above his right eye sustained in the 2-2 draw with Ghana on Saturday and still visible five days later.
The United States had a chance to level the match in stoppage time, but Alejandro Bedoya's low shot inside the box was swept away by the sliding Mario Goetze, a late substitute.
The Americans got a corner but Clint Dempsey's header at the far post went high. Loew reshuffled his lineup by bringing in forward Lukas Podolski for Goetze and midfielder Sebastian Schweinsteiger for Sami Khedira.
Center back Geoff Cameron was replaced in the US lineup by Omar Gonzalez. There were many empty seats in the Arena Pernambuco when the match kicked off but fans streamed in during the first half, apparently delayed by traffic jams as torrential rain flooded parts of this northeastern Brazilian city.
Germany was quicker off the mark and Howard intercepted a low cross from Podolski before Michael Bradley made a good clearance and Gonzalez defended well to deny Mueller a shot from close range.
Howard's 103th cap was a record for a US goalkeeper and he did well to stop Ozil's shot in the 35th minute. Graham Zusi had the first good shot for the US but his effort in the 22nd went high.
Referee Ravshan Irmatov of Uzbekistan collided accidentally with Jermaine Jones in the 28th and the American midfielder went down hard but got up.
The referee shrugged off the challenge. Miroslav Klose came on for Podolski at the start of the second half but failed to score and grab sole possession of the World Cup scoring record that he now shares with Brazil's Ronaldo at 15.
Ozil beat Gonzalez to a cross at the start of the second half but sent his header high, while Klose connected with a cross from Schweinsteiger but was off balance and did not get off a clean header.
Ronaldo earns Portugal 2-1
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.
Ronaldo slammed in the winner with his left foot in the 80th minute to break his drought in Brazil and give Portugal its first win.
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.
He barely celebrated his strike in the Brazilian capital, knowing his team still needed more goals, or a seismic turn of events in Recife, if Portugal was going to sneak into the last 16 at the Americans' expense.
In the end, Ronaldo actually 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.
Being awarded man of the match will be of little significance to the world player of the year. 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.
It was perhaps no surprise that Ghana delivered its most subdued display of the tournament, allowing Ronaldo time and space to enjoy his most lively performance in Brazil.
He walked off at halftime with his head down and likely wondering how he hadn't opened his account in this World Cup by then.
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. Ghana finished bottom of the group.