KABUL, Afghanistan — The future of U.S. involvement in Afghanistan after the last troops leave at the end of 2014 may depend on whether U.S. officials like Secretary of State John Kerry can allay Afghan President Hamid Karzai’s worries about sovereignty, Pakistan and the safety of Afghan citizens at the hands of Western troops.
Kerry began urgent talks Friday with Karzai as an end-of-October deadline loomed for a security deal that would allow American troops to remain in Afghanistan after the NATO-led military mission ends next year.
Kerry’s unannounced visit to Kabul comes as talks on the bilateral security agreement have foundered over issues of Afghan sovereignty despite a year of negotiations.
Discussions have stalled over Karzai’s demand for American guarantees against future foreign intervention from countries like Pakistan and U.S. demands for any post-2014 residual force to be able to conduct counterterrorism and counterinsurgency operations.
U.S. officials insist they are optimistic about a deal, but the continuing deadlock leaves it doubtful that any agreement will be reached by the deadline. If no deal is signed, there will be no U.S. forces in Afghanistan after 2014.
They said uncertainty caused by the lack of a signed agreement by the deadline would make it more difficult to plan the next phases of withdrawal from Afghanistan and could erode the resolve of NATO allies that are considering leaving troops there for training.
Without the United States on board, it is unlikely that NATO or any of its allies would keep troops in Afghanistan. Germany has already indicated it will not commit the 800 soldiers it has promised.
‘‘That’s why we’re pressing,’’ said one of the officials traveling with Kerry.
However, the officials, who spoke on condition of anonymity because they were not authorized to publicly preview Kerry’s discussions with Karzai, stressed that Kerry is not expecting to clinch an agreement during his visit.
Instead, the trip, which Kerry and Karzai set up in an Oct. 5 phone call, is meant to build momentum for the negotiators who will continue their talks after Kerry departs, the officials said.
The atmosphere surrounding the talks has been soured by recent angry comments from Karzai complaining about the conduct of NATO forces.
One possible reason for the complaints could have been the capture of a senior Pakistani Taliban commander by U.S. forces on the same day Kerry and Karzai last spoke.
Pakistani intelligence officials, Pakistani Taliban and Afghan officials said Latif Mehsud was arrested by American forces as he was driving along a main highway. Karzai saw the move as an infringement on Afghan sovereignty.
Mehsud is a senior deputy to Pakistani Taliban leader Hakimullah Mehsud. The Pakistani Taliban has waged a decadelong insurgency against Islamabad from sanctuaries along the Afghan border and also helped the Afghan Taliban in their war against U.S.-led troops in Afghanistan.
As part of the agreement, Afghanistan wants America to guarantee such cross-border activity won’t occur. Afghanistan accuses its neighbor of harboring the Taliban and other extremists who enter Afghanistan and then cross back into Pakistan where they cannot be attacked by Afghan or U.S.-led international forces.
Earlier this week, Karzai alleged that the U.S. and NATO inflicted suffering on the Afghan people and repeatedly violated his country’s sovereignty. The comments drew a sharp response from NATO’s secretary-general who recalled how much the alliance has bled in Afghanistan.
Nearly 3,390 members of the NATO coalition have been killed since the U.S. invasion, which marked its 12th anniversary on Oct. 7. They include at least 2,146 members of the U.S. military.
There currently are an estimated 87,000 international troops in Afghanistan, including about 52,000 Americans.
The U.S. wants to keep as many as 10,000 troops in the country to go after the remnants of al-Qaida, but if no agreement is signed, all U.S. troops would have to leave by Dec. 31, 2014.
The agreement would give the U.S. a legal basis for having forces in Afghanistan after that date and also allow it to lease bases around the country. It would be an executive agreement, meaning the Senate would not have to ratify it.
President Barack Obama acknowledged in an interview with The Associated Press last week that keeping troops there would require an agreement, and without one, he would be comfortable with a full pullout of U.S. troops.
The officials with Kerry said the differences were ‘‘complex’’ and not easily overcome.
Another sticking point is about the role and conduct of the counterterrorism force the U.S. wants to leave behind. Karzai has said the Afghan people cannot allow foreign troops to attack and kill Afghans on Afghan soil.
Karzai is calling a meeting of Afghan tribal elders to advise him on whether to sign a security deal. But that conference will not be held until November, Afghan officials say.
If they endorse the agreement, then Karzai has political cover to agree to it. He is keenly aware that previous leaders of his country historically have been punished for selling out to foreign interests and wants to make sure that any U.S.-Afghan agreement is not seen in that context. Karzai, who cannot run for a third term, is slated to step down at the end of next year — the same time nearly all international troops are to have left the country.
In addition to the security talks, Kerry will be seeking assurances from Karzai on preparations for the election to replace him, the officials said.
Associated Press writer Patrick Quinn contributed to this report.