– Just five days after taking office, over dinner with his newly installed secretary of defense and the chairman of the Joint Chiefs of Staff, President Donald Trump was presented with the first of what will be many life-or-death decisions: whether to approve a commando raid that risked the lives of U.S. Special Operations forces and foreign civilians alike.

President Barack Obama’s national security aides had reviewed the plans for a risky attack on a small, heavily guarded brick home of a senior Al-Qaida collaborator in a mountainous village in a remote part of central Yemen. But Obama did not act because the Pentagon wanted to launch the attack on a moonless night and the next one would come after his term had ended.

With two of his closest advisers, Jared Kushner and Steve Bannon, joining the dinner at the White House along with Defense Secretary Jim Mattis and Gen. Joseph F. Dunford Jr., Trump approved sending in the Navy’s SEAL Team 6, hoping the raid early last Sunday would scoop up cellphones and laptop computers that could yield valuable clues about one of the world’s most dangerous terrorist groups. Vice President Mike Pence and Michael T. Flynn, the national security adviser, also attended the dinner.

As it turned out, almost everything that could go wrong did. And Wednesday, Trump flew to Dover Air Force Base in Delaware to be present as the body of the American commando killed in the raid was returned home, the first military death on the new commander-in-chief’s watch.

The death of Chief Petty Officer William Owens came after a chain of miscues and misjudgments that plunged the elite commandos into a ferocious 50-minute firefight that also left three wounded and a $75 million aircraft deliberately destroyed. There are allegations — which the Pentagon acknowledged Wednesday night are most likely correct — that the mission also killed several civilians, including some children. The dead include, by the account of Al-Qaida’s branch in Yemen, the 8-year-old daughter of Anwar al-Awlaki, the U.S.-born Qaida leader who was killed in a targeted drone strike in 2011.

Trump on Sunday hailed his first counterterrorism operation as a success, claiming the commandos captured “important intelligence that will assist the U.S. in preventing terrorism against its citizens and people around the world.” A statement by the military’s Central Command on Wednesday night that acknowledged the likelihood of civilian casualties also said the recovered materials had provided some initial information helpful to counterterrorism analysts. The statement did not provide details.

But the mission’s casualties raise doubts about the months of detailed planning that went into the operation during the Obama administration and whether the right questions were raised before its approval. Typically, the president’s advisers lay out the risks, but Pentagon officials declined to characterize any discussions with Trump.

A senior administration official said that the Defense Department had conducted a legal review of the operation that Trump approved and that a Pentagon lawyer had signed off on it.

Trump’s new national security team — led by Flynn, the former head of the Defense Intelligence Agency and a retired general with experience in counterterrorism raids — has said that it wants to speed the decisionmaking when it comes to such strikes, delegating more power to lower-level officials so that the military may respond more quickly.

Indeed, the Pentagon is drafting such plans to accelerate activities against the Al-Qaida branch in Yemen. But doing that also raises the possibility of error.

“You can mitigate risk in missions like this, but you can’t mitigate risk down to zero,” said William Wechsler, a former top counterterrorism official at the Pentagon.

In this case, the assault force of several dozen commandos, which also included elite troops from the United Arab Emirates, was jinxed from the start. Al-Qaida fighters were somehow tipped off to the troops’ stealthy advance toward the village — perhaps by the whine of U.S. drones that local tribal leaders said were flying lower and louder than usual.

Through a communications intercept, the commandos knew that the mission had been somehow compromised, but pressed on toward their target roughly 5 miles from where they had been flown into the area.

“They kind of knew they were screwed from the beginning,” said one former SEAL Team 6 official.

With the crucial element of surprise lost, the Americans and Emiratis found themselves in a gun battle with Al-Qaida fighters who took up positions in other houses, a clinic, a school and a mosque, often using women and children as cover, U.S. military officials said in interviews this week.

The commandos were taken aback when some of the women grabbed weapons and started firing, multiplying the militant firepower beyond what they had expected. The Americans called in airstrikes from helicopter gunships and fighter aircraft that helped kill some 14 Al-Qaida fighters, but not before an MV-22 Osprey aircraft involved in the operation experienced a “hard landing,” injuring three more U.S. personnel on board. The Osprey, which the Marine Corps said cost $75 million, was badly damaged and had to be destroyed by an airstrike.

The raid, some details of which were first reported by the Washington Post, also destroyed much of the village of Yakla, and left senior Yemeni government officials seething. Yemen’s foreign minister, Abdul Malik Al Mekhlafi, condemned the raid Monday in a post on his official Twitter account as “extrajudicial killings.”

Baraa Shiban, a Yemeni fellow for Reprieve, a London-based human rights group, said he spoke by phone to a tribal sheikh in the village, Jabbr Abu Soraima, who told him: “People were afraid to leave their houses because the sound of choppers and drones were all over the sky. Everyone feared of being hit by the drones or shot by the soldiers on the ground.”

After initially denying there were any civilian casualties, Pentagon officials backtracked somewhat Sunday after reports from Yemeni authorities began trickling in and grisly photographs of bloody children purportedly killed in the attack appeared on social media sites affiliated with Al-Qaida’s branch in Yemen.

Capt. Jeff Davis, a Pentagon spokesman, said Monday that some of the women were combatants.

The operation was the first known U.S.-led ground mission in Yemen since December 2014, when members of SEAL Team 6 stormed a village in southern Yemen in an effort to free an American photojournalist held hostage by Al-Qaida. But the raid ended with the kidnappers killing the journalist and a South African held with him.

That mission and the raid over the weekend revealed the shortcomings of secretive military operations in Yemen. The United States was forced to withdraw the last 125 special operations advisers from the country in March 2015 after Houthi rebels ousted the government of President Abdu Rabbu Mansour Hadi, the Americans’ main counterterrorism partner.

The loss of Yemen as a base for U.S. counterterrorism training, advising and intelligence-gathering was a significant blow to blunting the advance of Al-Qaida’s branch in the country and keeping tabs on their plots. The Pentagon has tried to start rebuilding its counterterrorism operations in Yemen, however. Last year, U.S. special operations forces helped Emirati troops evict Al-Qaida fighters from the port city of Mukalla.