The site had been under surveillance, and the operation against an al-Qaeda-affiliated group had been in the planning stages, for months, current and former Obama administration officials said Monday. A drone strike against the al-Shabab compound had been rejected, officials said, because there were too many women and children inside, the same reason that the commander opted against an airstrike once the operation was underway.

Destroying the compound probably would also have defeated a primary purpose of the mission: to capture, not kill, a Kenyan-­born al-Shabab commander named Abdulkadir Mohamed Abdulkadir, also known as Ikrima. He has long been on a U.S. “capture or kill” list, along with al-Shabab leader Mukhtar Abu Zubeyr, known as Godane, and was considered the group’s primary planner of attacks outside Somalia.

As they provided more details of the aborted operation in the town of Barawe, current and former administration officials said it was designed within restrictive counterterrorism guidelines that President Obama signed in the spring. Under the 2001 congressional Authorization for the Use of Military Force, the guidelines say that lethal force can be used only when there is a “near certainty that non-combatants will not be injured or killed.”