The U.S. military has taken custody of two high-value Islamic State detainees accused of involvement in executing American hostages, officials said, as the Trump administration scrambles to ensure that militants imprisoned by Kurdish forces in Syria do not go free amid a military assault by Turkey.

The move, a rare instance in which the United States has taken direct responsibility for Islamic State prisoners in Iraq and Syria, comes as Ankara’s military operation forces U.S. officials to take steps to prevent the Islamic State from regaining strength.

As part of that response, military officials have moved the two British men — Alexanda Kotey and El Shafee Elsheikh — to Iraq. Officials are also weighing whether to take roughly 40 other individuals, all considered important Islamic State figures, into U.S. custody or transfer them as well.

The prisoners previously had been held in a constellation of small prisons in northeast Syria run by Syrian Kurdish forces who have been the Pentagon’s primary partner against the Islamic State in Syria. The Kurds are now pulling guards from those facilities to confront the unfolding Turkish assault.

The British pair — part of a group of four British militants dubbed the “Beatles” by their hostages — were being detained with the goal of putting them on trial in the United States, said a senior U.S. official, who like others spoke on the condition of anonymity to discuss a sensitive matter.

“We are taking some of the most dangerous ISIS fighters out,” President Trump said at the White House on Wednesday, using an acronym for the Islamic State. “We are taking them out and putting them in different locations, where it’s secure. . . . We have a certain number of ISIS fighters that are particularly bad, and we wanted to make sure that nothing happened with them in respect to getting out.”

He later confirmed in a tweet Thursday that the ones taken out included the so-called Beatles. “The United States has already taken the 2 ISIS militants tied to beheadings in Syria, known as the Beetles, out of that country,” he said, calling them “the worst of the worst.”

A criminal prosecution in the United States rests on the ability to obtain evidence from British authorities — a matter being litigated in the Supreme Court of the United Kingdom. In recent days, Attorney General William P. Barr asked Trump to make securing the detention of the two men a “priority” so they could be eventually prosecuted in the United States, and the president “immediately agreed,” according to a person familiar with the matter who spoke on the condition of anonymity to discuss internal deliberations.

The British men are accused of involvement in the beheading of Americans James Foley, Steven Sotloff and Peter Kassig, as well as other Western hostages.

The Turkish attack on Kurdish forces raised concerns about the ability of the Kurds to maintain control over thousands of Islamic State detainees and tens of thousands of women and children housed in separate camps, some of which are militant supporters.

“This is like a victory for the ISIS fighters. I just think it’s appalling,” said Diane Foley, James Foley’s mother. “It’s an abdication of our responsibility to ensure safety for our own citizens and allies.”

In a sign of the rapidly evolving U.S. response to Turkey’s offensive, which critics have said Trump enabled by pulling U.S. troops from the area south of Turkey’s border with Syria, U.S. officials said Wednesday that the administration was in the process of placing the approximately 40 suspected militants into military custody. On Thursday, the officials said they had completed that process with the two British men but were still considering whether to do the same with the larger group. 

While the move is directed at prisoners seen as the most threatening, military officials have said they have no orders to intervene if the Kurds abandon their prison posts. Trump has said Turkey is now responsible for those prisoners, a notion most analysts say is unrealistic.

“We now face the very real prospect of 10,000 ISIS prisoners rejoining the battlefield,” Sen. Jeanne Shaheen (D.-N.H.) said in a statement Wednesday.

Mohammed Emwazi, the man who killed Foley, Sotloff,  Kassig and other hostages in 2014, was killed in a drone strike the following year. A fourth American, Kayla Mueller, was killed while being held hostage by the Islamic State, but the exact cause of her death was not confirmed.

Kotey and Elsheikh had been in custody of the Kurdish-led Syrian Democratic Forces. Their potential transfer to the United States for trial has been delayed by Elsheikh’s mother, Maha Elgizouli, who has challenged the British government’s decision not to prosecute her son in Britain. She also has sued the British government to block any evidence-sharing with U.S. prosecutors without legal assurance that her son will not be executed.

“Mrs. Elgizouli is solely concerned to protect her son from the death penalty,” attorney Edward Fitzgerald said in a July hearing before the Supreme Court of the United Kingdom. “She recognizes that they should face justice. . . . But she submits that they should face justice in this country.”

British authorities for years have said they would prefer to see the two charged in the United States.

Prosecutors in the United States would seek to convict Kotey and Elsheikh as conspirators in hostage-taking resulting in death, a charge that carries a potential death sentence, U.S. officials said.

In an interview this summer, Kotey and Elsheikh denied involvement in any murders, saying they only facilitated ransom negotiations. Both men agreed to speak to The Washington Post, and Kurdish security officials facilitated separate interviews at a facility in Rmeilan, Syria.

Their role, both said, was to ask prisoners for contact information and personal details for “proof of life.” Kotey recalled having prisoners hold up signs urging their governments and families to “be quick or they will be kill me.”

At one point, Kotey said, a Syrian prisoner was shot in the back of the head in front of the European prisoners, who were made to hold signs saying they wanted to avoid a similar fate.

The British and American hostages were not included in that video, he said, because their governments were not negotiating.

“They were not pampered,” Elsheikh said. “The treatment had to be harsh to keep them in the state of mind” of compliance. “The prisoners had to be kept always under pressure.”

He said the harsh treatment included headlocks, punches and stress positions. But he denied any involvement in mock executions or waterboarding.

Kotey said he saw Emwazi, better known as “Jihadi John,” beat prisoners and threaten to waterboard them “as if he had previously” done so. He said Emwazi saw the killing of journalists and aid workers as warranted because they had “come to interfere in our internal affairs.”

Both Kotey and Elsheikh claim they were no longer working with Emwazi when the killing of hostages began. But they say they were among a very small group of Islamic State members who knew Emwazi’s true identity, first reported in The Post in early 2015.

A decision is expected in the coming weeks from the Supreme Court of the United Kingdom on whether the British government’s offer to share evidence on Elsheikh and Kotey, absent a promise from the United States that the men will not face the death penalty, violates British law.

Toby Cadman, a British lawyer representing Diane Foley, said he also worries that moving the prisoners around could create new opportunities for the defendants’ families to delay a prosecution.

“The last thing anyone wants is for the process to be . . . fudged in order to get them before a court that they can then challenge,” he said. “You want these people lawfully handed over.”

A fourth “Beatle,” Aine Davis, was convicted in Turkey of membership in a terrorist organization and sentenced to seven years in prison.

In its battle against the Islamic State, the U.S. military previously detained a dual U.S.-Saudi citizen in Iraq for more than a year before releasing him in 2018. 

Hina Shamsi, director of the American Civil Liberties Union’s national security project, said the U.S. detention of high-value detainees raised “a host of thorny issues that the military has sought to avoid, starting with its authority to detain people under domestic law.”

Many Pentagon officials have sought to minimize their involvement in the detention of terror suspects, a practice that was associated with scandals and legal challenges following the Sept. 11, 2001, attacks. 

“The military must abide by both domestic and international law, and not repeat the costly legal, moral, and strategic mistakes of abuse and unfair trials,” she said. 

This story was updated to reflect that the Trump administration is still considering what to do with the larger group of about 40 high-value detainees after taking the two British men suspected of involvement in hostage executions into U.S. custody. 

Mekhennet reported from Rmeilan, Syria. Khabbat Abbas and Louisa Loveluck in Rmeilan contributed to this report.