South Africa scored twice in the first half and held on for a 2-1 win over 10-man France at Free State Stadium in Bloemfontein on Monday.
South Africa (1-1-1) needed a one-sided result in the Mexico-Uruguay game to advance in the World Cup, but a 1-0 win for the Uruguayans means it will be the two countries from the Americas who will qualify for the knockout stage from Group A.
Bafana Bafana becomes the first host nation in the 80-year history of the tournament not to make it out of the group stage.
"Of course we're disappointed we did not quality but I do not consider this a failure," South Africa coach Carlos Alberto Parreira said. "I believe the whole country is proud."
Bongani Khumalo scored with a header to give South Africa a 1-0 lead after Siphiwe Tshabalala lofted the ball over French goalkeeper Hugo Lloris. Katlego Mphela scored later in the half with a loose ball marker near the goal line after France was reduced to 10 men.
France (0-2-1) crashed out of the World Cup, with Florent Malouda scoring midway through the second half for their only goal of the tournament. Yoann Gourcuff was shown a red card in the 25th for elbowing Macbeth Sibaya.
"I'm sad for all the fans and everyone who support the French team," France coach Raymond Domenech said. "It's the hard and harsh reality of our situation. So I have a genuine sense of sadness."
Mphela doubled the lead in the 37th after missing a strong chance earlier, outmuscling defender Gael Clichy to reach a low cross from Tsepo Masilela and shoot the ball across the line.
France made it 2-1 when Malouda knocked in a cross from Franck Ribery.
After playing with a lone striker in its first two matches, Parreira opted to play two men up front against France — Bernard Parker and Mphela — and it paid off.
Mphela caused trouble for the French defence, with strong runs and dangerous drives from distance. He nearly scored his second goal in the 43rd with a right-foot drive from 25 yards that forced a diving save from France goalkeeper Hugo Lloris.
Mphela continued to bother France's backline after the break, and should have scored in the 50th when he ran onto a pass from Steven Piennar, but his right-foot shot hit the crossbar.
The striker went close again five minutes later with a drive from 25 yards that Lloris punched away.
South Africa's attacking style brought the crowd at Free State Stadium to life, and the home fans roared with each Bafana Bafana foray into the French half.
Facing a 2-0 halftime deficit, Domenech brought on Malouda and striker Thierry Henry to try to boost his team's flagging attack.
The changes had little impact until Ribery set up Malouda.
South Africa finished with four points like Mexico, but deferred due to goal differential.
"Everyone knows and sees this group was one of the most tough groups in the World Cup," Parreira said. "Then we just didn't qualify because of our goal difference — with a little bit of luck, we should have qualified."
France were the 1998 champions and reached the final in 2006, having also been knocked in the first round in 2002.
There was widespread dissension among the French players over Domenech's tactics during the tournament, with striker Anelka sent home after the second game.
Domenech made six changes to the starting lineup from the squad that lost 2-0 to Mexico.
Anelka was sent home on Saturday, two days after a heated argument with Domenech at halftime of the Mexico match. The players then protested his expulsion by refusing to train on Sunday, with captain Patrice Evra believed to be among those spearheading the mutiny.
Evra was dropped from the starting lineup on Tuesday. Djibril Cisse replaced Anelka in attack. Domenech also selected Sebastien Squillaci, Gael Clichy, Andre-Pierre Gignac, Alou Diarra and Gourcuff.
Midfielder Jeremy Toulalan was ineligible after receiving two yellow cards in the tournament.
The match was Domenech's last for France. Laurent Blanc, who played on the '98 championship squad, is expected to take over.
"I'm sad. This team has great potential. I have loved the French team," Domenech said. "This team never dies and it has everything it needs to succeed with players that are coming up through the ranks."