During a testy video conference in June, President Obama drew a line in the sand for Afghan President Hamid Karzai. If there was no agreement by Oct. 31 on the terms for keeping a residual U.S. military presence in Afghanistan, Obama warned him, the United States would withdraw all of its troops at the end of 2014.

With that deadline less than three weeks away and deep rifts persisting, the White House appears increasingly willing to abandon plans for a long-term, costly partnership with Afghanistan. Despite the Pentagon’s pleas for patience, much of the rest of the administration is fed up with Karzai and sees Afghanistan as a fading priority amid far more ominous threats elsewhere in the world.

Secretary of State John F. Kerry arrived in Kabul Friday on an unannounced visit in an effort to convince Karzai that the administration is serious.

“October 31st is our goal,” a senior administration official said. “The president has been clear. There can be no reason” for failure “other than the fact that the Afghans don’t want what we’re offering.”

Meanwhile, serious new irritants in the relationship have convinced Karzai that he was right to question American good faith in year-old negotiations on a deal. The accord is considered critical for the international community to continue funding the Afghan government and shoring up its nascent security forces.

Under the Bilateral Security Agreement, or BSA, the United States plans to leave a still-unspecified number of troops — between 5,000 and 10,000, most probably — in Afghanistan to train and advise its security forces after the final withdrawal of what are now 52,000 combat and support troops.

Karzai was enraged several weeks ago, Afghan officials said, when U.S. forces forcibly took custody of a senior Pakistani Taliban leader whom Afghan intelligence was trying to recruit.

In the previously unreported incident, U.S. forces intercepted an Afghan government convoy and seized the leader in Logar province, Karzai spokesman Aimal Faizi said. In doing so, Faizi added, the Americans foiled a months-long bid by the Afghan government to wean the Taliban commander, identified by others as Latif Mehsud, from the battlefield and use him to help launch substantive peace talks.

Faizi called the seizure a major breach of sovereignty. Although Karzai has not mentioned the case publicly, his private fury has been reflected in recent suggestions that Afghanistan might forgo a bilateral pact.

In a separate incident, Pakistan last month freed a top Afghan Taliban official, Abdul Ghani Baradar, whom Karzai sees as a possible interlocutor for his peace efforts and whose release he had long demanded.

This week, however, Pakistan again placed Baradar under house arrest in the port city of Karachi. Karzai immediately suspected an American hand at work; U.S. officials said they feared that Baradar would return to plotting attacks against American forces in Afghanistan if he were left on the loose.

Both the CIA and the Defense Department declined to comment on either incident.

Karzai’s concerns

Karzai has expressed some legitimate concerns during the negotiations, such as those dealing with civilian casualties in U.S. air attacks, said the senior administration official, one of several who spoke on the condition of anonymity to discuss the state of negotiations.

But “some of them are frankly something between frustrating and offensive,” the official said. Most “unfathomable,” he said, is Karzai’s long-standing belief that the United States is colluding against him with Pakistan and the Taliban.

The official said that there would be no “magical event that occurs, that flips a switch,” at the end of the month and that there was always a possibility that some level of accord could still be concluded, either with Karzai or with a new president to be elected in April. “But it does represent a point at which we would have to reflect upon why it’s not done,” he said.

Pending a U.S. accord, other international partners have said that they would also leave forces behind, including a German contingent in northern Afghanistan and Italian troops in the west. Together, they would allow the State Department to maintain a secure diplomatic and development presence outside of the protection of the U.S. Embassy in Kabul.

The international community has also pledged to spend at least $4 billion a year after 2014 on equipping and otherwise assisting Afghan security forces, as well as an additional $4 billion in economic and development assistance. The bulk of the money would come from the United States.

None of these plans is likely to go forward if the BSA is not finalized.

Serious divisions

When negotiations began in November, success seemed a foregone conclusion. Unlike in Iraq, where last-minute failure to negotiate a continued U.S. presence led to an abrupt and total withdrawal at the end of 2011, Afghanistan expressed a strong desire for the Americans to stay. And unlike Iraq, Afghanistan desperately needs the financial and security support.

The October deadline was also seen as crucial to avoid letting the negotiations become an issue in the Afghan election campaign, which began last week.

Although much of the BSA is complete, the remaining issues of contention include U.S. insistence on freedom to conduct intelligence and counterterrorism operations against what it says are the depleted remnants of al-Qaeda. Afghanistan wants all intelligence shared.

But the most serious dispute is over Karzai’s push for a pledge of U.S. defense against any outside intervention. That, U.S. officials say, is code for protecting Afghanistan against Pakistan. U.S. refusal to grant what it says would require a Senate-ratified treaty is seen by Karzai as proof of U.S.-Pakistani collusion at his expense.

Similarly, officials said, Karzai views unilateral U.S. talks with the Taliban as evidence of American roadblocks in the path of his own negotiations with the militants. The administration has insisted that its primary goal is to facilitate Afghan government peace negotiations.

Karzai’s objections to a plan for the Taliban to open an office in Qatar, and the collapse of a nascent Taliban deal with the United States on a possible prisoner exchange, immediately preceded his angry conversation with Obama in late June.

This summer, the administration considered restarting low-level talks in Qatar, where Taliban representatives remain in a luxury hotel, about small-scale initiatives and the prisoners. But Defense Secretary Chuck Hagel successfully argued in a recent meeting with Kerry and national security adviser Susan E. Rice that there should be no such U.S.-Taliban contact until the completion of the BSA.

All U.S. departments with a presence in Afghanistan, one official said, have been asked to draw up plans for what the U.S. role in the country would look like without a BSA. For the State Department, the absence of U.S., German or Italian troops would mean closing the U.S. Consulate in Herat and scrapping plans for diplomatic facilities in Mazar-e Sharif and Kandahar.

The official said the Pentagon has responded with plans for a 600-troop presence, inside the embassy compound.

A senior defense official disputed that account, saying that “we are only planning for options that assume the BSA is done.”

Former deputy assistant defense secretary David Sedney, who until May oversaw Afghanistan policy, said there was deep concern in defense circles that the administration has failed to pay enough attention to Afghanistan over the past year amid a flurry of domestic and overseas crises.

“It appears our attention to Afghanistan is drifting, and if we don’t do something soon, it may drift too far to recover,” he said.

One official noted that both Obama and Rice appear only marginally interested as attention has shifted to Syria and a growing al-Qaeda presence in Africa.

“If you look at the threat matrix,” this official said, “Afghanistan isn’t blinking the brightest. Why invest more billions and more lives?”

Kevin Sieff in Kabul contributed to this report.