President Hamid Karzai has hedged on signing a security pact which would allow some US troops to stay in Afghanistan, putting himself at odds both with Washington and with an Afghan assembly.
The "loya jirga" assembly of 2,500 chieftains, tribal elders and politicians on Sunday overwhelmingly endorsed the agreement to permit some US soldiers to remain after 2014, the year when most of NATO's 75,000 combat troops pull out.
The meeting urged Karzai to sign the deal promptly.
But the president did not indicate when the deal would be inked, and said it would only go ahead under certain conditions.
US Secretary of State John Kerry said the assembly's vote was a "compelling affirmation from the Afghan people themselves of their commitment to a long-term partnership with the United States".
"Very significantly, the loya jirga also urged that the Bilateral Security Agreement (BSA) should be signed before the end of the year," he said.
Supporters say the BSA is vital for the period after 2014 because the Afghan government remains fragile despite 12 years of war against Taliban insurgents.
The Taliban, who before the assembly had threatened to target delegates if they backed the agreement, condemned the pact.
The "illegal and insignificant pact of slavery with America will neither benefit the American invaders nor criminal slaves", they said in a statement referring to the jirga members.
Opening the assembly in Kabul on Thursday, Karzai exasperated Washington by saying he wanted to delay signing the BSA until after the successful completion of April's presidential election.
After four days of discussions under tight security, jirga delegates anxious to conclude the deal with Afghanistan's main financial and military partner said in their closing statement that Karzai should sign before the end of 2013.
"Given the current situation, and Afghanistan's need... the contents of this agreement as a whole is endorsed by the members of this Loya Jirga," they said.
Peace, or 'disaster'
However, Karzai set conditions including US "cooperation" in efforts to make peace with the Taliban, and said he would "work on the agreement and continue bargaining".
Karzai also appeared to toughen his stance on US military raids on Afghan homes, a sensitive topic that threatened to derail the deal last week.
"If the US goes into Afghan homes one more time, there will be no agreement," he said, repeating the point for emphasis.
In the days before the jirga his spokesman said Kabul and Washington had agreed to allow US raids but only in "exceptional circumstances" in which the lives of US troops were in danger.
That wording was echoed in a letter from President Barack Obama to Karzai though it did not appear in the draft BSA text released by Kabul on the eve of the jirga.
Kate Clark, senior analyst with the Afghan Analysts Network, said that with the BSA unsigned, Karzai retains some bargaining power.
One explanation for his sudden imposition of conditions on a deal the US thought was concluded, she wrote on the AAN website, was that he is genuinely concerned about what happens once the Americans have the BSA.
"As Karzai said on the first day of the jirga, there is no trust between them. He does not believe their assurances," she wrote.
"He wants to hold on to some form of leverage, as, in his mind, this is the only way to force the US to refrain from stomping over Afghan sovereignty."
The pact must be approved by the Afghan parliament before it can go into effect. But the question of when it would be signed has largely overshadowed discussions of its content in recent days.
The US State Department warned that failure promptly to sign the pact could jeopardise billions of dollars in vital aid to the war-torn country.
The White House has said it needs a swift decision to start planning the movement of US troops, and warned that Obama had not yet decided whether to keep any American forces in Afghanistan at all beyond 2014.
A draft text of the BSA released by Kabul last week appeared to show Karzai had bowed to a US demand that American troops would remain exempt from Afghan jurisdiction if they are accused of crimes.