KABUL, Afghanistan — The two candidates for president of Afghanistan have agreed on a power-sharing deal that will give the losing candidate substantial influence in the next government, initialing the American-brokered deal Saturday night and promising to sign it at a formal ceremony on Sunday.

The deal, confirmed by a spokesman for the Afghan president, promised an end to the tumultuous, five-month aftermath of the Afghan presidential election, although previous settlements have collapsed at the last minute despite the candidates’ promises. Under the deal, the top vote-getter, Ashraf Ghani, would become president but would grant significant powers to the loser, Abdullah Abdullah, according to a draft of the four-page agreement obtained by The New York Times and authenticated by Western diplomats and campaign officials.

Mr. Abdullah, or someone he nominates, would effectively become the prime minister.

The agreement on forming a national unity government was completed last Sunday, with the two candidates planning to sign it last Tuesday. At the last minute, however, Mr. Abdullah said he would sign only if the results of an audit of the election, determining the final tally for each candidate, were not publicly released.

He has insisted that the results were so tainted by fraud that they should never be made public.

Although it was unclear how that issue was resolved, an Abdullah campaign official said on Saturday the deal had been initialed and would be formally signed Sunday.