MONROVIA, Liberia — For decades, Liberia has waited through war and strongmen for a peaceful democratic transfer of power. On Thursday, as the last ballots in a presidential election were being tallied, that appeared to be on the verge of happening.

Unofficial elections returns showed that George Weah, a former international soccer star, defeated the sitting vice president, two former warlords and his own ex-girlfriend and won the right to succeed the first woman democratically elected as president of an African country.

It was Mr. Weah’s third bid to lead Liberia, a nation founded almost two centuries ago by freed American blacks. He will succeed Ellen Johnson Sirleaf.

In electing Mr. Weah, Liberian voters are investing in him hopes that he can build on one certain accomplishment of Mrs. Sirleaf: keeping the country out of war. But Mrs. Sirleaf’s government has also been plagued with corruption charges, high unemployment and a shambolic health system that is still trying to regain its footing after the devastation of the 2014 Ebola epidemic, which killed more people in Liberia than anywhere else.