KABUL - An Afghan grand assembly Sunday endorsed a crucial security agreement allowing some US troops to stay on after 2014, although President Hamid Karzai set conditions for signing the deal.

The "loya jirga" gathering of about 2,500 chieftains, tribal elders and politicians overwhelming backed the pact setting the terms for any US military presence beyond 2014, and urged Karzai to sign it by the end of this year.

Karzai did not explicitly address when the deal would be signed, but said it would only go ahead under certain conditions.

Taliban insurgents, 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 on Thursday, Karzai said he wanted to delay signing the Bilateral Security Agreement (BSA) until after the successful completion of April's presidential election - exasperating Washington, which wants it sealed quickly.

Supporters say the BSA is vital for the period after 2014, when the bulk of NATO's 75,000 remaining troops will pull out, as the Afghan government remains fragile despite 12 years of war against Taliban insurgents.

Karzai laid out conditions for signing the BSA, including US "cooperation" in efforts to make peace with the Taliban, who have led the 12-year revolt against Karzai's government and its foreign backers.

"This agreement should lead to peace. If it does not lead to peace, it will lead to disaster," he said.

"The Americans should cooperate, and bring peace. If this agreement leads to peace, on my eyes, I will endorse, and accept your order and sign it."

After four days of discussions under tight security in Kabul, jirga delegates anxious to conclude the deal with Afghanistan's main financial and military partner said in their closing statement that Karzai should sign the BSA 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," said the statement read by jirga deputy Fazul Karim Imaq. Karzai also stipulated that there could be no more 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. I repeat, if they go into our homes one more time, there will be no agreement," he said.

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 President Barack Obama had not yet decided whether to keep any American forces in Afghanistan at all beyond 2014.

A spokesman for the US embassy in Kabul said the Americans "continue to believe that concluding the agreement as quickly as possible will benefit both nations".

Analyst Fardin Hashemi said that despite Karzai's comments he expected the deal to be signed soon.

"Afghanistan needs US aid to function and the continuation of the aid has been conditioned on a signing of the pact before the end of the year," he told AFP. The president told delegates he would "work on the agreement and continue bargaining" after they made recommendations for the deal.

These included the return of Afghan detainees held at the US prison camp at Guantanamo Bay in Cuba. They also asked that American soldiers accused of crimes in Afghanistan should be put on trial in courts on US bases in the country.

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.

A similar security deal between the United States and Iraq collapsed in 2011 over the same issue, leading Washington to pull its forces out. Karzai told delegates the BSA would allow up to 15,000 foreign troops to stay, though Washington has stressed that no final decision has been made.

Throughout the negotiations over the loya jirga, coalition officials had been deliberately silent, but this time they pushed back, at least on the military side.

“Unfortunately, some people are using allegations of civilian casualties for political purposes,” an International Security Assistance Force official said, speaking on the condition of anonymity as a matter of official policy.