Every once in a rare while, a cunning plan to stop an evil dictator works. At least for a time.

Such is the story of a geeky group of Pentagon scientists, State Department experts, and White House politicos who plotted together with top Russian officials to find and destroy Syria’s weapons of mass destruction—more than a year before they got the chance to actually do so.

Getting rid of those weapons had been a top priority for the Obama administration. The president had famously warned that if Syrian dictator Bashar al-Assad dared to use them on his own people, he would have crossed a “red line” that could trigger a U.S. military response.

Syria eventually agreed to relinquish its weapons and sign on to the Chemical Weapons Convention in 2013, and at the time, many attributed Assad’s acquiescence to an offhand comment by Secretary of State John Kerry, who said during a press conference that Syria could avoid punitive U.S. strikes if it got rid of its WMD. The Russian foreign minister seized upon Kerry’s offer and within days, a deal was struck.

What the public didn’t know is that planning between Washington and Moscow had been underway to get rid of Syria’s weapons since the fall of 2012, spurred by doomsday scenarios spelled out by top U.S. officials.

The series of secret talks, held in luxurious locations across Europe, led to a meeting of the minds between arch frenemies U.S. and Russia, followed by rapid-fire tinkering worthy of 007’s Q to create the means to destroy one of the largest uncontrolled chemical weapons stockpiles in the world.

“We realized we in the U.S. didn’t have the capacity to destroy Syria’s chemical weapons—that nobody did,” Andrew Weber, then Assistant Secretary of Defense for Nuclear, Chemical, and Biological Defense Programs, told The Daily Beast.

Something entirely new had to be built.

The success of the talks to come could have served as a blueprint for future negotiations between the U.S., Russia and other world powers to stop the Syrian civil war meat grinder, except for one thing: It took the threatened use of force against the Syrian regime to convince the Russians to pry those weapons from Assad’s hands.

When Assad’s troops used the nerve agent sarin (PDF) against his own people in the Damascus suburb of Ghouta in August 2013, the Obama administration threatened a punitive bombing run against Assad’s military—not enough to disarm it, but enough to make a point.

Only then did Russia strong-arm its client state into giving up its WMD crown jewels—likely with the promise to defend Assad in return, which Russia has since done by deploying Russian troops on Syrian soil and unleashing a relentless series of airstrikes on Assad’s opponents, including Syrian rebels backed by the U.S.

But for a brief shining moment, the U.S. and Russia had worked together to disarm the regime.

The Obama administration’s Syria WMD nightmare kicked off back in 2011, when the country began to fall apart, with province after province giving way to unrest and regime attacks.

Senior administration officials from the White House to the Pentagon mapped out where they thought Syria’s WMD stockpiles were located, and they war-gamed the worst possible scenarios, including what would happen if the weapons fell into rebel hands.

“We had break-glass books” for every possible outcome, one senior administration official explained, speaking on condition of anonymity in order to discuss the high level planning. For instance, they spelled out who to call and what to say if the rebels approached a chemical weapons depot, with multiple variables depending on which group and how good U.S. intelligence was about them.

The official described the internal debates: Do you tell the rebels where the WMD is, so they don’t bomb it or do you not tell them, in case rebel double agents overhear the information and feed it to terrorist groups, who would then make taking the site a priority?

“You see them stumbling toward a bunker where it was stored,” and panic would set in, the official said. “Lots of ways things could go bad.”

Then-U.S.-Ambassador-to-Syria Robert Ford was the “rebel whisperer,” the official said, transmitting these messages to various rebel groups through unspecified means.

And in the Pentagon, where experts construct imaginatively dark possibilities and how to defend against them, Weber’s team and others were coming up with plans to find, secure and destroy the WMD.

The options were grim: If chaos broke out and no one was in charge, how many troops would it take to secure all the suspected WMD sites? The answer: up to 75,000—unacceptable to an administration that didn’t want to put a single American soldier in harm’s way in Syria.

Weber remembers meeting with then-Deputy Secretary of Defense Ash Carter, who was worried the Assad regime would cause a “Chemical Srebrenica” with the WMD, a reference to the 1995 massacre that killed an estimated 7,000 Bosnian Muslims.

“Ash turned to me and said, ‘What would you suggest?’ I said, ‘I think we should work with Russia,’” Weber recalled. “Put it on trucks and drive it to Jordan to destroy it. People in the room looked at me like I had two heads.” But Carter nodded and wrote it down in his notebook, Weber said.

That kind of outside-the-box thinking, and his decades spent working with the Russians and others to track WMD is one of the reasons Weber’s real life has ended up retold in celluloid, with the Pentagon’s blessing. The 1997 George Clooney film The Peacemaker was based in part on his role in an operation codenamed Project Sapphire to secure WMD material in Kazakhstan. A man who cultivates the look of a bookish, baseball-cap wearing college professor rather than a movie star, he was also an advisor on the set of HBO’s Homeland with its WMD-focused plot line last season.

As the Syrian crisis passed its first year, Weber’s team was among the various doomsday committees that coalesced into a White House interagency group that was part group therapy, part apocalypse management.

They knew they would have to be ready to do something, after President Barack Obama served notice on Syria, in August 2012, that using WMD against its own people would constitute that “red line” for the U.S.

One administration official remembers the first fledgling talks between the U.S. and Russia on the fringe of another international meeting in a European capital. There was respect, if not trust, that had been built up over previous decades as they’d worked together after the fall of the Soviet Union to prevent mutually assured nuclear destruction.

The first time Weber heard the subject raised was when he took a trip to Moscow with now-retired Sen. Richard Lugar to discuss nuclear issues with the Russians.

The Indiana Republican pushed the idea of a joint U.S.-Russian mission to dismantle the Syrian program. Lugar mentioned his idea to reporters, and it scored a mention in The New York Times and caught Obama’s eye. Weber said the president called the senator to ask him if he thought the Russians would be willing to take part. Lugar relayed that the Russians were skeptical, but willing to listen.

The two sides finally started meeting in secret in September 2012, at first to discuss overall U.S.-Russian relations, at the storied President Hotel in Moscow.

“Maybe 7 or 8 of them, 10 or 12 of us,” a senior administration official related, describing the high level meeting of Obama National Security Council members and the Russian Security Council, including Russian Deputy Chief of General Staff Colonel-General Aleksandr Postnikov-Streltsov.

The first expert-to-expert meeting was held at the Russian embassy in Helsinki in December 2012, the official said.

“We discussed what we thought we each knew about the size of the arsenal and the technical means of destroying this… if such an opportunity arose,” the State Department’s Countryman said.

They shared their intelligence showing what each believed was the contents and location of Syria’s stockpiles. Their maps didn’t match, said the other senior official who was there at the start.

The American map was much more extensive than the Russian one, either because Russia didn’t know where the weapons were located or weren’t sharing. The Russians agreed to work using the American map.

They came up with something called the “universal matrix,” a sci-fi-sounding term that described all the steps one would take to dismantle a chemical weapons program.

They estimated there was 1,300 tons of sarin, mustard agent, and VX in Syria, a staggering amount. Pentagon engineers did the math and determined that it could be moved in 200 truckloads—if the Syrians could be convinced to relinquish the material.

Along the way, Pentagon planners tried to figure out how the rebels, the Americans, or some other country or group would destroy the stockpiles if they got their hands on it.

Military engineers studied massive hydrolysis facilities in the U.S. that had been used to dismantle old U.S. mustard agent stockpiles from wars gone by. The agent is now illegal for the U.S. to use since it signed on to the Chemical Weapons Convention.

And then they figured out how to shrink the facility.

“We invested in a prototype to be mounted inside two shipping containers because we had no idea where it would be used, and we wanted it to be transportable,” Weber said.

The first prototype was ready by June 2013, a record turnaround time for the cumbersome Pentagon acquisition process, which Weber later wrote about. The Pentagon ordered six more and waited for the high-level meetings to produce a chance to use them.

And then in August that same year, the Syrian regime took a step across the red line. Assad, his back against the wall because of the then-growing-effectiveness of rebel forces, started using WMD. The attack at Ghouta, which killed an estimated 1,500 people, kicked the Obama administration into action.

The administration was hours away from a strike. But at the last moment, Obama decided to seek congressional authorization for military action, staving off an attack that was hours away.

Obama’s threat was still enough to convince the Russians he was prepared to use force, all three former officials said.

A week later Secretary of State Kerry told reporters in London that Assad still had a way out.

“Sure, he could turn over every single bit of his chemical weapons to the international community in the next week—turn it over, all of it without delay and allow the full and total accounting (of it), but he isn’t about to do it and it can’t be done,” Kerry said.

Russian Foreign Minister Sergey Lavrov reached out, and the two men met in Geneva, and the old band got back together and came up with a plan to truck the WMD out of the country and then water it down using the high-tech trailers designed by the Pentagon. The work would be done on a ship somewhere in the Mediterranean. (They kept the location secret to stave off complaints from any nearby countries who didn’t want the chemicals in their backyard).

The U.S. and Russian experts came up with a nine-month deadline to remove and destroy everything—longer than the Americans wanted but shorter than the Russian officials thought possible.

“In retrospect, the nine-month deadline was exactly on the borderline of being technically feasible and utterly insane,” Countryman said. They did miss it by a few weeks, but were done by early August 2014 with the actual destruction.

“We are fully satisfied with the level of cooperation achieved with the United States partners that allowed us to quickly reach an agreement on the issue,” said Yury Melnik, the spokesman of the Russian Embassy in Washington. He said the success was large due to the Russian president’s decision to impose international control on Syria’s stockpiles.

“The chemical demilitarization of Syria is an example of how the international community can solve complicated problems related to non-proliferation of the WMD with well-coordinated and targeted efforts,” Melnik wrote in an email Saturday to The Daily Beast.

"The plan was implemented in a record period. My country was actively involved in practical steps,” after adding that Russia supplied special equipment for to safely transport the material at Syria’s request, as well as financial assistance, and that Russian Naval ships provided security during the removal of the toxic chemicals.

Did they get it all? Almost certainly not, which is why the Obama administration says they got 100 percent of the declared stockpiles, the current and former officials all said.

But when asked if removing the WMD instead of sending a volley of missiles in to bloody Assad’s nose handed him and Russia a victory, they bristle.

“You don’t understand what punishment means. We took away their strategic arsenal and destroyed it, under international supervision,” the senior administration official said. “That removed Assad’s backup plan.”

It also removed a strategic threat to ally Israel, the official added, which reportedly stopped handing out gas masks to the public after Assad’s weapons were dismantled. The Israeli embassy in Washington declined to comment on its gas mask policy.

“A military strike would not have taken out their chemical weapons,” but rather hit other Syrian military targets—anything but the suspected weapons sites, Weber said.

“Dropping bombs on chemical weapons is a stupid idea because it releases toxic weapons into the atmosphere and contaminates entire areas,” and could have accidentally killed thousands, he added.

Countryman said as bloody as the war has been, it could have been worse.

“If you consider that the quantity used at Ghouta in August of 2013 was less than 1 percent of the Syrian stockpile, and it managed to kill over a thousand people… there is a lot of ways you can calculate that,” said the diplomat, who has spent decades serving throughout the Middle East. “It was the largest uncontrolled chemical weapons stockpile in the world and now it’s essentially gone.”

Russia’s gut-punching march into Ukraine just months later in early 2014 obliterated any illusions the White House may have had about the chemical talks building a bridge between the two sides.

“It’s disappointing that less than six months later, we had this major exercise in trust destruction,” a senior official said.

And now that Russia has moved in troops, and sophisticated anti-aircraft batteries into Syria, it’s unlikely the U.S. would ever again threaten the use of force to stop Assad.

But at least neither Assad nor ISIS will have access to weapons that can kill thousands in a single strike.