Former finance minister Ashraf Ghani was declared Afghanistan's next president on Sunday, hours after signing a power-sharing deal with his rival Abdullah Abdullah that ended a prolonged standoff over the disputed result.
The "unity government" deal paves the way for a crucial bilateral security agreement (BSA) governing the presence of American troops in Afghanistan beyond 2014, with Washington voicing optimism that it will be signed soon.
Allegations of massive fraud in the June 14 vote sparked a political crisis as both candidates claimed victory, paralysing the country at a key moment with US-led troops winding down their 13-year war against the Taliban.
When the "unity government" deal was finally signed, Ghani embraced Abdullah briefly at a low-key ceremony in the presidential palace that lasted less than 10 minutes.
Abdullah will become "chief executive officer" (CEO), a role similar to prime minister -- setting up a tricky balance of power as Afghanistan enters a new era.
Neither candidate spoke at the palace ceremony, and it remained uncertain when they would address the nation or when the unity agreement would be officially published.
"The Independent Election Commission declares Dr Ashraf Ghani as the president, and thus announces the end of election process," commission chief Ahmad Yousaf Nuristani later told reporters.
"During the election process fraud was committed from all sides. That has concerned people."
In a move likely to trigger complaints over transparency, Nuristani gave no figures for the winning margin, turnout or the number of fraudulent ballot papers thrown out in an UN-supervised audit that checked every individual vote.
Ghani was widely acknowledged to be on the brink of the presidency after coming well ahead in preliminary results released before the audit began.
Under the constitution, the president wields almost total control, and the new government structure will face a major test as the security and economic outlook worsens.
"Hamid Karzai wishes the elected president Dr. Ashraf Ghani and the CEO Dr. Abdullah Abdullah success based on the agreement between them," said a statement from the outgoing president.
The vote count has been plagued by setbacks amid allegations of massive fraud, emboldening the Taliban insurgents and further weakening the aid-dependent economy.
As tensions rose in Kabul, the United Nations and United States pushed hard for a "unity government" to avoid a return to the ethnic divisions of the 1990s civil war, which ended with the Taliban taking power in 1996.
A ruling coalition between opposing camps is likely to be uneasy.
Abdullah, a former anti-Taliban resistance fighter and foreign minister, draws his support from Tajiks and other northern ethnic groups. Ghani, an ex-World Bank economist, is backed by Pashtun tribes of the south and east.
"There will be two powers in the government, and it will be very difficult for them to work together," Sediq Mansoor Ansari, an analyst and director of the Civil Societies Federation, told AFP.
"I think the people of Afghanistan will wonder about their votes, and how their votes have been played with."
The future of Afghanistan's relationship with the US-led NATO alliance will also be high on the agenda after Karzai refused to sign a security pact with Washington to ensure a foreign military presence after this year.
The White House welcomed the election result and the power-sharing deal, which it said "helps bring closure to Afghanistan's political crisis".
"We look forward to... the conclusion of the Bilateral Security Agreement (BSA)," it added in a statement.
The "unity government... offers a huge opportunity for progress in Afghanistan, for the signing of the BSA in a week or so," said US Secretary of State John Kerry.
According to a copy of the unity government document seen by AFP, the CEO could become the official prime minister in two years' time -- a major change to the strongly presidential style of government forged by Karzai since 2001.
Dividing up other government posts could also create friction after the long and mercurial reign of Karzai, who built up a nationwide network of patronage.
The UN's country director Jan Kubis lauded Sunday's announcements, but warned that "for the sake of the country, it is time to quickly implement the agreement".
The new administration will have to stabilise the dire economy as international aid falls, and deal with worsening unrest.
About 41,000 NATO troops remain in Afghanistan fighting the fierce Taliban insurgency alongside Afghan soldiers and police.
NATO's combat mission will end in December, with a follow-on force of about 12,000 troops likely to stay into 2015 on training and support duties.