* Kerry's visit seen as last-ditch effort before deadline
* Afghan traditional assembly to decide on outcome -Karzai
* Kerry and Karzai say all other major issues resolved
U.S. Secretary of State John Kerry and Afghan President Hamid Karzai on Saturday reached a preliminary agreement on a bilateral security pact that now depends on approval by Afghanistan's tribal leaders.
The pact, announced jointly by Kerry and Karzai after two days of talks in the capital, Kabul, would keep some U.S. forces in Afghanistan after 2014.
It includes a key U.S. demand to retain legal jurisdiction over the troops that will remain in Afghanistan, which would give them immunity from Afghan law.
It will be up to the country's Loya Jirga, an assembly of elders, leaders and other influential people, to decide whether to accept it.
"Tonight we reached some sort of agreements," Karzai told a news conference, speaking through an interpreter.
U.S. officials said they wanted the pact finalised by the end of October and Kerry's visit was seen as a last-ditch effort to push the deal through before the deadline.
The United States is insisting it cannot agree to a deal unless it is granted the right to try U.S. citizens who break the law in Afghanistan at home in the United States.
A senior U.S. administration official said the sides had agreed on language in the draft deal that covers the issue of immunity and "that can be put to his Loya Jirga for their consideration."
"We need to say that if the issue of jurisdiction cannot be resolved, then unfortunately there cannot be a bilateral security agreement," Kerry told a news conference.
Karzai said the talks had focused on protecting Afghan sovereignty and that major differences had been resolved, including a U.S. request to run independent counter-terrorism missions on Afghan territory.
Such operations carried out by the United States have long infuriated the Afghan president, who had been demanding Washington agree to share intelligence instead.
Karzai said the U.S. snatching of a senior Pakistani Taliban commander was an example of the kind of action that Afghanistan wanted to avoid.
"This is an issue that we have raised in earnest with the United States in the past few days as we have all previous occasions of such arrests in which the Afghan laws were disregarded," Karzai said, referring to the capture of commander Latif Mehsud.
"Therefore our discussion today in particular has been focused on making sure that through the bilateral security agreement such violations are not repeated."
Kerry attributed the complaint to a misunderstanding.
"We followed the normal procedures that the United States follows ... we did what we are supposed to do," he said.
The Afghan government rejected an initial U.S. proposal on immunity at the start of the year and it has been a sticking point ever since. The failure to reach a deal could prompt the U.S. to pull all its troops out after 2014, in an outcome known as the "zero option".
It was considered almost unthinkable a few months ago, but U.S. officials have since raised the possibility, with an implicit warning that Afghan security forces are not ready to fight the Taliban-led insurgency without their help.
The collapse of similar talks between the United States and Iraq in 2011 - partly over the issue of immunity - led to the United States completely ending its forces' mission there rather than maintaining a significant presence.
U.S. officials had said earlier that Kerry did not intend to close a deal on the Bilateral Security Agreement (BSA) during the visit, but Washington is concerned that as Afghan election campaigning intensifies, it will be harder to broker a deal.
Karzai's brothers this week began their campaign to take power and plan to offer the outgoing president, constitutionally barred from running again, a position in their government.
The April election is seen as the most crucial since the U.S.-led overthrow of the Taliban in 2001, which brought Karzai to power.
International aid donors, who provide Afghanistan with the bulk of its income, hope a transfer of power will enable the country to move beyond years of damaging allegations of corruption and maladministration.
In an interview this month, Karzai blamed corruption on irresponsible spending by donors and said coalition troops had brought nothing but suffering because security was still poor.
Security has been deteriorating, increasing worry about the country's prospects after Western forces leave. On Saturday, a car bomb killed four people in the eastern city of Jalalabad.
Efforts to draw the Taliban into negotiations have come to nothing. The militants say they will fight on until all foreign forces leave and they dismiss Karzai as a U.S. "puppet".
PROTECTING U.S. TROOPS
The Afghan president said the question of whether Afghanistan would be able to try U.S. citizens for crimes committed on its territory could not be decided by his government.
"The issue of jurisdiction is one such issue that is beyond the authority of the Afghan government and it is only and entirely up to the Afghan people to decide upon through two mechanisms," said Karzai, referring to the country's traditional assembly and its parliament.
Kerry said U.S. troops operated under the same standards wherever they were deployed.
"Wherever our forces are found, they operate under the same standard," he said. "We are not singling out Afghanistan."