The African National Congress lost its political stranglehold on South Africa after election results on Saturday showed that with almost all of the votes counted, the party had received only about 40 percent, falling short of winning an absolute majority for the first time since vanquishing Africa’s last white-led regime 30 years ago.

With South Africans facing one of the world’s highest unemployment rates, shortages of electricity and water, and rampant crime, the governing party still bested its competitors but could not sustain the nearly 58 percent of the vote it won in the last election, in 2019.

The staggering nosedive for Africa’s oldest liberation movement put one of the continent’s most stable countries and its largest economy onto an uneasy and uncharted course.

The party, which rose to international acclaim on the shoulders of Nelson Mandela, will now have two weeks to cobble together a government by partnering with one or more rival parties that have derided it as corrupt and vowed never to form an alliance with it.

“I’m actually shocked,” said Maropene Ramokgopa, one of the top officials in the African National Congress, or A.N.C. “It has opened our eyes to say, ‘Look, we are missing something, somewhere.’”

South Africa’s president, Cyril Ramaphosa, who leads the A.N.C., faces a grave threat to his ambition of serving a second term. He will be forced to summon the negotiating skills that famously helped him broker the end of apartheid, and pull together his highly factionalized party, which is likely to disagree on which party to ally with.