Image caption Hamid Karzai has long maintained opposition to US troops entering homes

The Afghan government has rejected a key proposal of a security agreement with the US, putting the entire deal in doubt days before Afghan tribal leaders gather in Kabul to consider the matter.

The government in Kabul is refusing to allow US forces to enter Afghan homes after combat operations end next year.

Negotiations are going on to produce a document acceptable to both sides, to present to Afghan elders on Thursday.

If there is no deal, Washington could pull out all its troops next year.

The US State department did not directly address the issue in a press briefing on Monday.

"We reached a general agreement on the BSA [bilateral security agreement] when Secretary Kerry was in Kabul just last month," said a state department spokeswoman, Jen Psaki, referring to talks between US Secretary of State John Kerry and Afghan President Hamid Karzai in October.

"This week the Loya Jirga [tribal assembly] will meet to consider the BSA. We of course respect the Afghan process and continue to work for a positive outcome. We believe that would be to the benefit of both countries."

Earlier, a spokesman for the Afghan president Hamid Karzai told the BBC's David Loyn in Kabul that there was no flexibility possible in the stand taken by his government over US forces entering Afghan homes and mosques.

He said President Karzai felt very strongly about this, and would not accept any agreement that would allow US forces to enter Afghan homes for what he called "the purpose of aggression".

President Karzai and other Afghan leaders have long maintained opposition to such US raids on Afghan homes.

But the US wants to continue to have the ability to prevent terrorist attacks coming from Afghanistan, and that could involve entering Afghan properties, our correspondent says.

The New York Times, quoting an Afghan official, says the commander of the US forces in Afghanistan, General Joseph Dunford, offered to modify the wording of the agreement to say that US troops would only enter homes "on extraordinary occasions". But the offer was reportedly rejected by Mr Karzai.

Recovery in jeopardy

The impasse reopens an issue that the US side thought it had made an agreement on weeks ago, says our correspondent.

In October, US Secretary of State John Kerry held talks with President Karzai, after which he said that they had resolved disagreements over the bilateral security agreement, although differences remained.

While the exact terms of what was agreed have not been revealed, Mr Karzai appeared to have secured US agreement not to carry out attacks on Afghan soil without first consulting the Afghan authorities.

But they failed to resolve another sticking point - who has jurisdiction for any crimes committed by US forces remaining in Afghanistan after 2014.

The failure to resolve this issue in Iraq led to a total withdrawal of US forces.

US immunity from prosecution will also be raised at the loya jirga of up to 3,000 Afghan elders.

Our correspondent says if the bilateral security agreement is not reached, US troops would withdraw next year, followed by all other international forces, with grave consequences for other aid donations, jeopardising Afghanistan's fragile recovery.