KABUL, Afghanistan — Afghanistan’s monthslong election dispute, which resulted in the bizarre reality of two men taking the oath of office as president, reached a resolution on Sunday when President Ashraf Ghani gave his chief rival, Abdullah Abdullah, the leading role in the country’s peace process with the Taliban and the right to appoint half the cabinet.
The deal ends a political crisis that cast a major shadow over efforts to end the country’s long war with the Taliban. The standoff complicated Afghan negotiations with the insurgents after the United States agreed with the Taliban to begin a phased troop withdrawal.
All but one of Afghanistan’s presidential elections since the 2001 American invasion have ended in dispute, and the most recent two brought the country to the verge of more bloodshed even as war with the Taliban raged. In 2014, Secretary of State John Kerry negotiated a power-sharing arrangement that kept Mr. Ghani as president and Mr. Abdullah as the government’s chief executive with half of the power.
After Mr. Abdullah disputed Mr. Ghani’s victory in clinching a second term in last September’s elections, both sides dug in. They refused to come together in one government even after the United States chided both leaders and cut $1 billion in aid.
As international pressure grew and the Taliban appeared to be benefiting from the political disarray, the two sides began talks to find a way out.
The new deal — whose negotiations were mediated by Afghan political leaders including former President Hamid Karzai — strips Mr. Abdullah of an executive role in the government but gives his coalition half the cabinet appointments. In return, Mr. Abdullah takes charge of the peace efforts with the Taliban in a new role as chairman of the High Council for National Reconciliation.
Mr. Ghani also agreed to the formation of a High Council of Governance, which will give major political leaders a role in advising the president in hopes of shaping a united front as Afghanistan seeks an endgame with the Taliban. Mr. Ghani struggled to create political consensus in his first five years in office, alienating many influential political figures.
“I am proud that today the ranks of the republic are united in reaching the sacred goal of peace and stability,” Mr. Ghani after signing the deal.
The agreement splits up responsibilities in a way that fits the two leaders’ strengths.
Mr. Ghani is deeply technical and enjoys the weeds of governance and system-building. He now gets his wish of undivided executive authority at the top after a first term of having to share with Mr. Abdullah, who occupied a prime ministerial role of sorts based on the previous coalition deal negotiated by the United States.
Mr. Abdullah has built a career out of rallying clashing groups. His skills of building consensus will now be tested as he tries to unite a deeply divided Afghan political elite around peace negotiations. This also gives him a shot at building a legacy by playing a central role in ending a decades-old war.
“I had said that I was ready for any sacrifice for peace,” Mr. Abdullah said Sunday. “I dedicate myself to it.”
At the signing ceremony the two men struck a forward-looking tone. But analysts said implementing the deal would not be easy, considering the bitter election disputes the two teams have faced.
“The deal will make the format of peace talks with the Taliban easier in that there is a head of the reconciliation council now,” said Shukria Barakzai, a former member of Parliament and a diplomat. “But the details will still remain difficult. For example, if Mr. Abdullah agrees with an issue, does that mean President Ghani will also, or vice versa?”
The Afghan government, meanwhile, has dragged its feet on the Taliban condition of releasing up to 5,000 of their prisoners before direct talks. After much pressure from American officials, the Afghan government agreed to a phased release, which has moved at a snail’s pace.
The violence reached brutal new heights last week when, within an hour, militants attacked both a maternity ward in Kabul and a crowded funeral in Nangarhar Province in the east. At least 24 people were killed in the rampage at the hospital, 16 of them women who had gone there to give birth. Afghan officials have said two babies were also among the dead.
“Last Tuesday, the eyes of our children that had just been opened to this world were shut,” former President Karzai said Sunday at the signing ceremony. “This tells of our painful reality; it can’t get more painful than this. We want our country to be secure as soon as possible — that neither the government nor the Taliban fire another bullet in this land.”
This was Mr. Abdullah’s third consecutive time disputing an election before striking a deal, which has given him a reputation as someone who always gives in. His own allies questioned how far he would go. When Mr. Ghani took the oath of office as president in February, Mr. Abdullah disputed the results and went along with pressure from his own coalition for a parallel swearing-in just next door to Mr. Ghani. On their official social media accounts, both men used the title of president.
But soon after, facing international pressure and chiding from the United States, Mr. Abdullah showed a willingness to compromise again — much to the anger of some supporters. As a sign that he wanted to resolve the dispute as quickly as possible, he personally negotiated the deal. Negotiating for Mr. Ghani were his national security adviser, Hamdullah Mohib, and his former intelligence chief, Masoom Stanekzai.
The compromise was made more palatable to Mr. Abdullah by satisfying the wish of his most powerful backer, Gen. Abdul Rashid Dostum, and giving Mr. Abdullah cabinet positions to dole out to other supporters. General Dostum, a controversial former vice president to Mr. Ghani who switched sides to Mr. Abdullah, will be promoted to marshal, the highest military rank.
A strongman championing Afghanistan’s ethnic Uzbek minority through four decades of wars and politics, General Dostum has an open court case against him. The case centers on accusations made in 2016 by Ahmad Ishchi, a political rival who said that while he was vice president, General Dostum had abducted him from a crowded sports arena, tortured him and ordered his rape.
As General Dostum’s supporters celebrated on Sunday, his daughter posting pictures of the two with a cake, Mr. Ishchi’s family complained that their cries for justice had been ignored.
“Someone who has a case” of such gravity “is promoted to marshal as a result of this deal,” said Baktash Ishchi, Mr. Ishchi’s son.
Moments after signing the agreement, Mr. Abdullah changed his Twitter bio, dropping his title as “The president of the Islamic Republic of Afghanistan.”
Fahim Abed contributed reporting.