Germany beat Ghana 1-0 after a second-half goal from Mesut Oezil to win Group D and set up a second-round World Cup clash with traditional rival England.
Ghana also advanced despite Wednesday's loss at Soccer City and became the first African team to make the round of 16 at the first World Cup held on the continent.
"It was a tense game. We could have made more out of our opportunities," Germany coach Joachim Loew said. "We were not very precise up front. But I can't blame my young players, there was a lot of pressure, we had to win. And now we are really looking forward to England.
"It's going to be a special game, there is so much history between us. It's a team with many excellent players and a lot of experience. [Wayne] Rooney can explode any time, we'll have a tough job."
Germany will play Group C runner-up England on Sunday in Bloemfontein (CBC, CBCSports.ca 9:30 a.m. ET).
Germany won the group with six points and Ghana was second with four, going through on goal difference thanks to Australia's 2-1 victory over Serbia in the other match.
Oezil rifled a left-footed shot from outside the area into the left corner of the net to break the deadlock in the 60th minute after both teams had wasted a number of chances.
Little time to celebrate
"I simply shot the ball, but I should have scored in the first half too," said Oezil, who was voted man of the match. "I had a lot of support from my teammates. It doesn't matter whom we play next, we have to keep winning."
"I am very relieved to have scored because I had missed many chances in the tournament," Oezil added.
Once the scoreboard had flashed the result of the other match, Ghana players celebrated their progress, waving the country's flag and running to the corner where their supporters were.
The Black Stars went through thanks to their 1-0 win over Serbia and a 1-1 draw with Australia.
"It was a very difficult match but we fought and it was enough to get us through," said Ghana midfielder Andre Ayew. "We had opportunities but the important thing is that we went through."
Ghana will play the United States on Saturday in Rustenburg.
"There is no time to celebrate, the next match is very close," Ghana's Serbian coach Milan Rajevac said. "We knew it would be a tough match because to try to qualify against Germany is really hard. We played quite well, we resisted well, we had some chances but they had to win and they showed that they are among the best teams in the world."
Rajevac said he hoped the South Africans, whose team was eliminated, would throw their support behind his team.
Germany had been in danger of failing to advance from the group stage for the first time but the three-time champions had the upper hand throughout the match, without taking unnecessary risks.
"It was good for my young team to be in a make-or-break situation," Loew said.
Germany captain Philipp Lahm said his team had been under "enormous pressure."
"But we didn't get nervous and now we are already looking forward to England," Lahm said.
Ghana also had some chances and Kwadwo Asamoah ran through in the 51st minute but shot weakly at goalkeeper Manuel Neuer.
Oezil was clear in the 25th but Ghana goalie Richard Kingson blocked his shot.
In the first half, Ghana's Asamoah Gyan had a header from a corner cleared at the post by Lahm, and Kevin-Prince Boateng's header was wide.
Jerome Boateng, Kevin-Prince's half brother, played for Germany. The two had little contact during the game.
It was Kevin-Prince's foul in the English FA Cup final that forced Germany captain Michael Ballack out of the tournament with an injury.
Loew had said before the game that Germany would not target Kevin-Prince. Jerome Boateng, who was making his World Cup debut, had said before the game that the two half brothers had not spoken to each other since the start of the tournament.
"It was important for him not to get cautioned and keep his cool. I thought the German players were very correct with him,"Rajevac said.
The two players have the same Ghanaian father and different German mothers. They were born and grew up in Germany, and Kevin-Prince played for Germany's junior teams before switching allegiance.