WASHINGTON — As two Islamic State militants faced a judge in Virginia, Diane Foley listened from home through a muffled phone connection. She strained to make out the voices of the men prosecutors say kidnapped her son before he was murdered.

Alexanda Kotey and El Shafee Elsheikh stand accused of belonging to an IS cell dubbed “the Beatles,” an incongruously lighthearted nickname for Britons blamed for the jailing, torture and murder of Western hostages in Syria.

After geopolitical breakthroughs and stalemates, military actions in Syria and court fights in London, the Justice Department’s most significant terrorism prosecution in years was finally underway in October. For Foley, who months earlier had pleaded with Attorney General William Barr to secure justice by forswearing the death penalty, that the case was happening at all felt miraculous.

“We’d met so many blocks over the years, I couldn’t believe it was happening,” Foley said. “I was in awe of it, really, and almost didn’t trust it — a bit incredulous. Is this really happening?”

The prosecution is a counterterrorism success in the Trump administration’s waning months. But it almost didn’t happen.

Interviews with 11 people connected to the case make clear the hurdles along the way, including a death penalty dispute that required two normally close allies, the U.S. and U.K., to navigate fundamental differences in criminal justice systems. In the end, the interviews show, grieving families reached a gradual consensus to take capital punishment off the table while a key commitment by Barr to do the same enabled the U.S. to obtain crucial evidence it needed.

“There was never a time when I thought we didn’t have any case,” said John Demers, assistant attorney general for national security. But, “we didn’t want to bring them here unless we had really good charges, a really strong case, and ultimately expected a conviction that was going to result in a very significant prison sentence.”

The group of militants, called “the Beatles” by their captives because of their British accents, came to embody IS barbarism with the 2014 release of grisly propaganda videos depicting the beheadings of American hostages. The first showed James Foley, who was captured as a freelance journalist covering Syria’s civil war, kneeling in the desert in an orange jumpsuit beside a masked man in black brandishing a knife to his throat.

An airstrike killed that man, known as Jihadi John, the group’s most notorious member. Another member was prosecuted in Turkey.

Kotey and Elsheikh were captured in Syria in 2018 by American-backed Syrian forces.

“There was never a time when I thought we didn't have any case." But, “we didn't want to bring them here unless we had really good charges, a really strong case, and ultimately expected a conviction that was going to result in a very significant prison sentence."

- John Demers, assistant attorney general for national security

Inside the Justice Department, officials weighed whether the men should be tried in the U.K. or U.S. or even transferred to the U.S. military prison at Guantanamo Bay, Cuba.

U.S. officials initially leaned toward a U.K. prosecution. British authorities had accumulated compelling evidence, and U.S. policy encouraged other nations to repatriate and prosecute their citizens who’d joined IS.

But the U.K., which had stripped the men of their British citizenship, resisted doing the case, in part over concerns about the ability to get convictions and significant prison terms.

The British also imposed a condition on any prosecution the U.S. might bring, refusing to share evidence without assurances the U.S. wouldn’t seek the death penalty, which was abolished in the U.K. U.S. officials considered such evidence vital.

The British eventually relented, agreeing to share evidence without the assurances. But Elsheikh’s mother sued, and, last March, a British court effectively blocked the evidence-sharing.

Despite the ruling, prosecutors pressed forward. G. Zachary Terwilliger, the U.S. attorney for the Eastern District of Virginia, whose office is handling the prosecution, argued internally that getting the defendants to the U.S. was more important than leaving the death penalty on the table.

The families, too, began uniting around the idea of removing the death penalty from consideration. That was notable because they had not always held the same views of the case.

The executions of Foley and two other hostages, Steven Sotloff and Peter Kassig, were documented in propaganda videos, the men’s fates apparent to the world.

But the circumstances of the death of a fourth, Kayla Mueller, who prosecutors say was sexually abused by late IS leader Abu Bakr al-Baghdadi, were less established. Her parents initially believed keeping the death penalty on the table could be leverage to get answers.

Mueller’s mother, Marsha, said in a text message the couple had not wanted anyone to die but simply wanted information. Ultimately, though, when it came to the death penalty, “The other families who we care so deeply for wanted the men brought here and this seemed to be the only way they would come.”

Current and former FBI officials who had been advising the families encouraged them to speak out to prod the Trump administration. Ali Soufan, a former FBI counterterrorism agent, told the families that the straightest path to justice involved waiving the death penalty.

Other options were hardly optimal. The likelihood of a legitimate trial in Iraq, where the men were being held in U.S. military custody, was uncertain. And proceedings there would risk a human rights outcry.

During the summer, as the families made clear their wishes to remove the death penalty from consideration and as the case dragged on without an obvious resolution, Barr agreed to break the logjam.

Barr vowed in an Aug. 18 letter to U.K. Home Secretary Priti Patel that the U.S. government would forgo the death penalty, and said if the Justice Department received the evidence by Oct. 15, it would proceed with prosecution. If not, the U.S. would transfer the men to Iraqi custody.

The evidence came, resulting in a 24-page indictment with terrorism counts punishable by life in prison.