Secretary of State John Kerry said Wednesday he had nailed down terms governing the presence of US troops in Afghanistan beyond 2014, just hours before Afghan leaders debate the deal.
Kerry said he had "reached an agreement as to the final language of the bilateral security agreement that will be placed before the loya jirga tomorrow" in a slew of phone conversations with President Hamid Karzai.
A draft text released by Kabul appeared to show Karzai had bowed to a US demand that American troops would not be tried in local courts if they are accused of crimes -- an issue that became a big hurdle in the negotiations.
The text is now set to go before the loya jirga, a traditional Afghan assembly, on Thursday.
The Bilateral Security Agreement (BSA) is seen as vital to security in the war-torn nation, where the Islamic Taliban insurgency this year has reached levels of violence not seen since 2010, according to the United Nations.
A similar deal between the United States and Iraq collapsed in 2011 over the issue of whether American troops would be answerable to local courts, leading Washington to pull its forces out.
But the draft text, published on the Afghan foreign ministry website, said Kabul had agreed that the United States should have "the exclusive right to exercise jurisdiction" over its forces in Afghanistan.
"Afghanistan authorizes the United States to hold trial in such cases, or take other disciplinary action, as appropriate, in the territory of Afghanistan," it said.
According to the draft, the deal will remain in force "until the end of 2024 and beyond" with international forces planning to withdraw unless either side ends it.
The issue dogged the negotiations with Kabul, leading some to fear the Iraq "zero option" would be repeated and the country would plunge deeper into violence as local forces struggle to quell the Taliban.
Afghan officials could not be reached for comment after the document's publication. It remains unclear how many US troops will stay on after the majority of NATO forces, who currently number 75,000, pull out.
Kerry said the remaining forces would have "a very limited role, it is entirely train, equip, and assist. There is no combat role for the United States forces."
Afghan officials have said up to 16,000 could remain, but the announcement is expected to come separately from US President Barack Obama.
The draft deal also said that while American military operations against Al-Qaeda may be "appropriate" in the fight against terrorism, the two sides would cooperate closely to protect US and Afghan interests "without unilateral US military counter-terrorism operations."
There was no mention however of another sticking point -- on whether US troops will be able to search Afghan homes.
Aimal Faizi, Karzai's spokesman, told reporters in Kabul on Tuesday that it had been agreed that US forces could search homes, but only in "extraordinary circumstances" where there was an urgent risk to life.
Threatening to overshadow the crucial last steps on the BSA, an unexpected row later blew up after reports that the US would apologize for mistakes made during the Afghan war.
Kerry said there had never been such a discussion.
"President Karzai didn't ask for an apology, there was no discussion of an apology, it's just not even on the table," Kerry said.
The United States could however provide Afghan leaders with some kind of "reassurances about our security relationship in addressing past issues such as civilian casualties," State Department spokeswoman Jen Psaki said.
It was unclear though whether those reassurances would be made in a "letter or come in another format," she added.
Civilian casualties and incidents such as the accidental burning of Korans in February 2012 have caused huge anger and resentment among Afghans.