U.S. Secretary of State John Kerry, left, and Russian Foreign Minister Sergei Lavrov, right, deliver statements in Geneva, Switzerland, on Saturday. (Martial Trezzini/AP)

By midday Friday in Geneva, progress had been made in nearly round-the-clock meetings between U.S. and Russian negotiators and experts on Syria’s chemical weapons, but it was not enough.

Although the two sides were close to agreement on the size and location of the Syrian arsenal, they remained far apart on other issues, including how to collect and destroy the weapons. It was clear that the Russians would not agree to a U.N. Security Council resolution that authorized an automatic use of force if the Syrians reneged on any deal.

And Russian Foreign Minister Sergei Lavrov was packing up to go home that night.

As the two sides gathered at the table after lunch, Secretary of State John F. Kerry successfully appealed to Lavrov, saying that he and his team would stay as long as it took. He would talk into the night, he said. He would get up as early as necessary the next day.

According to a State Department official’s account of the negotiations, which began Thursday evening and ended Saturday afternoon with a framework accord to secure and eliminate Syria’s chemical weapons, it was a deal that almost did not happen.

In the end, the deal was written entirely by the U.S. side. The Russians agreed to it in an impromptu poolside conversation between Kerry, Lavrov and their deputies, who dragged over chairs to join them. Kerry made final edits to the draft on an iPad in his hotel room.

The version of events offered Sunday by the senior State Department official, who spoke on the condition of anonymity to discuss the closed-door conversations, was both riveting and self-serving. Russian officials offered no recounting of their own, except to emphasize that the deal was their idea, discussed in general terms over the past year but not seriously addressed until they proposed it last week.

Syrian President Bashar al-Assad, who had no representative in Geneva, was similarly closemouthed. In an interview with RIA Novosti, the Russian news agency, Syrian National Reconciliation Minister Ali Haidar said the agreement would “help Syrians come out of the crisis” and had “prevented the war against Syria by having removed a pretext for those who wanted to unleash it.”

In Moscow, the Foreign Ministry refused to comment on the course of the Geneva talks, but the newspaper Kommersant reported that the Russian delegation was unsure until almost the end whether the United States would accept international control of Syria’s chemical weapons. If Kerry had balked, the effort would likely have collapsed.

The Russian press portrayed the agreement as a diplomatic triumph for Russia, though noting that the outcome was beneficial to the United States and President Obama as well.

Not everyone agreed.

“It is Putin and not Obama at all who is applauded for prevention of the war in Syria,” Alexei Pushkov, head of the foreign affairs committee of the lower house of parliament, wrote in a tweet. “Half the world backed Russia in this tug-of-war with the United States.”

Nikolai Zlobin, a political analyst, was quoted in the Vedomosti newspaper as saying that, having shouldered responsibility for the agreement on Syria, “Russia will have a lot on its plate.”

Another newspaper, Nezavisimaya Gazeta, said Saturday’s agreement could turn out to be the turning point in the Syrian crisis.

Kommersant said the three days of talks will one day be treated as chapters in History of Diplomacy courses.

The broad-brush accord left many gaps, and the coming week will indicate whether it has the potential to quickly eliminate Syria’s weapons, whether it has definitively ended the threat of U.S. military intervention and whether it has any bearing on the Syrian civil war, now in its third year.

But as told by the senior U.S. official, the United States and Russia — each backing a different side in the conflict — have recommitted themselves to trying to end the war.

Kerry spent Thursday afternoon in Geneva huddled with aides and the group of weapons experts who had flown across the Atlantic with him. “There was agreement that we would not accept just any deal,” the senior official said. “We had to pass a bar that included timelines, specifics and a path to the U.N., and we had to be able to sell it to the rest of the world and to the United States Congress.”

Before their first meeting Thursday evening, Kerry and Lavrov held a news conference. Kerry made a lengthy speech, outlining U.S. goals for the talks. Lavrov, to the surprise of the U.S. team, said little.

While Kerry and Lavrov dined on fish and salad, the U.S. team came out of an initial session with their Russian counterparts “feeling both sides were talking past each other and we needed to figure out a different way to break through. This wasn’t going to work on the current path.”

The two sides were “miles away” from each other on their assessments of the size of the weapons stockpiles. The team called in intelligence analysts from both sides, who sat down to thrash out their differences.

After the Russians left, the U.S. team concluded in a late-night meeting that the fact that Lavrov had provided only a two-page document of Russia’s ideas was an opportunity for the Americans to drive the discussions. Working groups were assigned to write proposals on a timeline, how procedures outlined in the international Chemical Weapons Convention could be used as a template and how any accord could be guaranteed by a Security Council resolution that would not be met with an automatic Russian veto.

While Kerry and Lavrov met with U.N. envoy Lakhdar Brahimi on Friday morning, the technical teams narrowed their difference on the scale of the stockpile. “There was agreement from both sides that a deliverable from the conference would be a framework document” that the U.S. delegation agreed to write while experts worked to plug additional holes of disagreement, the senior official said.

But when working groups convened after lunch, “there were rumors and threats that the Russians would leave at 10 p.m. that evening,” the official said.

As Kerry appealed to Lavrov, he mentioned a breaking story in the media. U.N. Secretary General Ban Ki-moon, meeting with a women’s group in New York, had been quoted as saying that U.N. inspectors who had investigated an alleged Aug. 21 chemical attack outside Damascus had significant evidence that it had taken place and that it was massive, and would report their findings to the Security Council on Monday.

The Americans “sensed a small shift on the Russian side,” the official said, and Lavrov left the meeting, saying he was going to the nearby Russian Embassy for consultations with Moscow. He returned and said he would stay for an additional meeting the next day.

After the framework agreement was announced Saturday, the official said, Kerry got a congratulatory call on his cellphone from Obama as he took a walk in the hills overlooking Lake Geneva.

Will Englund in Moscow contributed to this report.