Germany's Thomas Mueller scored his fourth World Cup goal to pull level with Lionel Messi and Neymar in a 1-0 win over United States on Thursday that gave his side top spot in Group G.
The United States, coached by former German boss Jurgen Klinsmann, also went through to the last 16 despite the defeat in rain-sodden Recife. Portugal's 2-1 victory over Ghana was not enough to overtake the Americans in second place.
In the other game, Cristiano Ronaldo wasted a succession of glorious chances as Portugal bowed out of the World Cup on Thursday despite beating Ghana 2-1 in Brasilia.
Portugal knew only a win combined with a defeat for Germany or the United States in the other Group G fixture, plus a significant swing in goal difference, would take them through to the last 16.
Although Ronaldo netted his first goal of the tournament, the winner, it was his numerous misses that cost Portugal the sizeable victory they needed to make up for the 4-0 mauling they suffered by Germany in their first game.
The lead-up to match at Recife had focused on suspicions that the Germans and Americans would be happy with a draw that would give both sides an easy path through to the next round.
Klinsmann's friendship with his former assistant German coach Joachim Loew had reinforced the conspiracy theories. But Germany dominated the match in the washed-out Arena Pernambuco.
US goalkeeper Tim Howard repeatedly kept his side in the game for 55 minutes until Mueller broke the deadlock.
A well-worked corner saw Howard save from Per Mertesacker's header.
The rebound went to Mueller on the edge of the penalty area who made no mistake with a powerful first-time shot that flew past the flying goalkeeper into his left corner.
Germany could have had several goals in an entertaining first half in which Howard played the key role.
The United States soaked up the early pressure, and on a rare foray midfield orchestrator Michael Bradley sent Graham Zusi through on the left for the winger to unleash a drive that sailed just over Manuel Neuer's crossbar.
Portugal had taken the lead through a John Boye own goal before Asamoah Gyan equalised.
The Europeans broke the deadlock after half an hour with an own goal by the unfortunate Boye, who diverted a cross by Miguel Veloso off his knee and over despairing goalkeeper Fatawu Dauda.
Kevin-Prince Boateng and Sulley Muntari had been sent home after attacking and abusing, respectively, members of the Ghana management.
Ronaldo, after a scrappy opening few minutes he picked the ball up wide on the right and hit a wayward cross that sailed over Dauda only to come back off the crossbar.
He then tried his luck with a free-kick from 25 yards in a central position which Dauda beat away.
The 29-year-old looked certain to score as he rose unmarked to meet a cross from seven yards out but headed straight at Dauda, who made an instinctive reaction parry.
The Black Stars put pressure on Portugal after the break, with captain Gyan producing a shot from just outside the penalty area that skimmed narrowly wide.
Shortly before the hour mark Ghana's persistence earned reward when Gyan headed home at the far post from a sublime cross by Kwadwo Asamoah, delivered with the outside of his left boot.
Gyan thus became the top African goalscorer at World Cups with his sixth effort in finals.