Recife, Brazil: Germany's Thomas Mueller stayed on track to retain his Golden Boot title at the World Cup by scoring his fourth goal of the tournament in the 1-0 victory over the United States.
The outcome allowed both teams to advance. Portugal beat Ghana 2-1 in the other Group G match but both were eliminated.
A draw would have been enough as well, and it had been the matter of much conjecture before Thursday's match at the rain drenched Arena Pernambuco. But neither team held back and both attacked, although Germany was clearly in control.
With two wins and a draw, Germany topped the group with seven points, while the U.S. progressed with four.
Mueller scored in the 55th minute with a side-footed shot from the edge of the area. He now has nine goals in nine World Cup games.
Germany, a three-time champion, now travels to Porto Alegre to play the runner-up in Group H on June 30.
Brasilia, Brazil: Cristiano Ronaldo finally made his mark at the World Cup -- but it came too late to spare Portugal an early exit from Brazil.
The world player of the year broke his scoring drought at the tournament with an 80th-minute winner against Ghana.
That result left the Portuguese level on four points with United States in Group G but with an inferior goal difference to the second-place Americans, who lost 1-0 to Germany in Recife. Ghana also was eliminated, finishing bottom of the group.
"We knew we had to score three goals and were depending on the result of the Germany game and we couldn't do that," Ronaldo said.
Ronaldo barely celebrated after slamming home his goal, giving Portugal its first win after a 4-0 loss to Germany and 2-2 draw with the U.S.
Ghana captain Asamaoh Gyan's 57th-minute header canceled out an own goal scored by teammate John Boye in the 31st, and at that stage it was the African side that was closer to qualifying.
A 2-1 victory would have put Ghanaians through but Majeed Waris' headed chance that he planted wide of the post in the 60th was the only genuine opening they created before Ronaldo's clincher.