U.S. Secretary of State John Kerry extended talks on Saturday with President Hamid Karzai on a bilateral security agreement with the United States, and while work remains to be done a deal could be struck by the end of the day, a presidential spokesman said.

Mr. Kerry began negotiations with Mr. Karzai on Saturday morning, the second day of talks after he arrived late on Friday. Discussions had repeatedly stalled in recent weeks over Mr. 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.

The U.S. wants a deal by the end of the month, while Mr. Karzai wants assurances over sovereignty that have deadlocked negotiations in the past year.

The situation deteriorated in the past week following a series of angry comments from Karzai that the United States and NATO were repeatedly violating Afghanistan’s sovereignty and inflicting suffering on its people.

The agreement is necessary to give the U.S. a legal basis for having forces in Afghanistan after the end of 2014 and also allow it to lease bases around the country. It would be an executive agreement, meaning the U.S. Senate would not have to ratify it.

There currently are an estimated 87,000 international troops in Afghanistan, including about 52,000 Americans. That number will be halved by February and all foreign combat troops will be gone by the end of next year.

The U.S. wants to keep as many as 10,000 troops in the country to go after the remnants of al-Qaeda, but if no agreement is signed, all U.S. troops would have to leave by December 31, 2014. President Barack Obama said in an interview with The Associated Press he would be comfortable with a full pullout of U.S. troops.

Mr. Karzai is calling a meeting of Afghan tribal elders in November to advise him on whether to sign a security deal. — AP