Habemus Praesidentem: there's white smoke in Kabul – figuratively speaking.

And like choosing a pope, selecting Afghanistan's new president has been a long and enigmatic process. Candidate registration began on Sept. 16, 2013. The first round of voting was on April 5. The second round on June 14.

And now, on Sept. 21, Afghan election officials announced that Ashraf Ghani is the country's the next president. He'll succeed President Hamid Karzai, who has ruled since the fall of the Taliban in 2001.

At times it wasn't clear that the election would ever be resolved. From the moment polls closed on June 14, Abdullah Abdullah alleged the election had been rigged against him. After preliminary results were released in early July, Abdullah declared he would not accept the results and he threatened to form his own government.

That prompted Secretary of State John Kerry to fly in and broker a deal. Under that agreement, both candidates would accept the outcome of an audit of all the votes cast in the runoff election. The second part of the deal was that Abdullah and Ghani would agree to form a government of national unity once the winner was declared.

The agreement took two months to hammer out. It was finally signed in a quiet ceremony at the presidential palace Sunday. Before a roomful of Afghan dignitaries and President Karzai, the two candidates inked the final draft of a national unity agreement. They shook hands, hugged, and took their seats.

President Karzai welcomed the agreement.

"We all pray that Afghanistan reaches peace and prosperity by the help of god," Karzai said. "This agreement has brought hope for the people."

The thrust of the deal is the creation of a new position, a chief executive who will be appointed by the president. The CEO, presumably Abdullah, will have less power than a prime minister but will participate in "decision-making meetings," sit on the national security council and chair cabinet subcommittees.

Cabinet positions and members of the national security council will be divided between Abdullah and Ghani.

The agreement calls for a reform of the flawed electoral system. It also calls for a Loya Jirga (grand assembly) in two years to discuss amending the constitution to create a formal position of executive prime minister.

Part of the reason the negotiations took so long is because the preliminary results announced in early July showed Ghani with a large lead. That put his team in the position of negotiating as the presumptive winner.

Both candidates also had to answer to a host of powerful backers who wanted as much as possible out of the agreement. One of Abdullah's supporters made repeated threats to launch protests and occupy government buildings if Abdullah didn't get enough out of the deal.

And in the last few days, a new disagreement emerged. Abdullah wanted the announcement of the final results not to use the terms "winner" and "loser" — and to withhold the actual vote count. Essentially, it appeared to be a play to save face.

In its announcement today, the election commission completely ignored the outcome of the U.N.-supervised audit and simply said Ghani is the new president. There was no mention of the final audited numbers, prompting significant outcry on Twitter.

Reaction to the agreement on social media has been swift and divided. Many Afghans call the agreement a victory for peace and stability. They see it as the beginning of a new chapter for Afghanistan. Statements from the U.S., UN, and EU echo this sentiment.

But other Afghans are fiercely critical. They say this negotiated outcome subverts democracy. They say the vote of the people is not being respected and this is essentially creating two winners.

And there is criticism that this was a deal imposed on Afghanistan by the U.S.

There are also fears the deal will not last. Given the country's personality-based politics and weak public institutions, there are concerns the agreement will eventually break down.

Copyright 2016 NPR. To see more, visit http://www.npr.org/.