But to Washington, Libya these days is largely ungoverned space, with its government’s ability to control the country in rapid decline. Mr. Bash, now a managing director at Beacon Global Strategies in Washington, said it was possible that parts of Libya’s government were aware of the operation despite official protests on Sunday. But he said, “Our interests are not always aligned with theirs, and sometimes we have to act because they lack either the will or the capability, or both.”

The Libya raid traces its origins to last year, according to the administration official, when national security agencies believed they had an understanding of the whereabouts of Abu Anas and began formulating a plan to capture him. Abu Anas, who was indicted in 2000 in the 1998 bombings of American Embassies in Kenya and Tanzania, was a much-coveted target, but in addition to the logistics of capturing him, government officials had to consider the legalities.

The plan to go after him was discussed repeatedly by officials known as the deputies committee, composed of No. 2 officials from across government, before it was refined and sent to cabinet secretaries for their recommendation and finally to Mr. Obama.

The Somalia operation came together more recently, just in the last few months, after simmering debate inside the government about whether direct assault missions were worth the risk to American lives.

State Department officials in particular have argued that such missions would have little strategic value and questioned whether Shabab, the Somalia-based extremist group that said it was behind an attack by gunmen in a shopping mall in Nairobi, Kenya, last month that killed dozens of people, was anything more than a regional nuisance. The administration until now has relied on troops from other African countries, trained by American private contractors, to fight Shabab forces in Somalia. But last month’s attack in Nairobi led some American officials to reconsider Shabab’s ability to sow chaos beyond Somalia’s borders.

In terms of diplomatic relations, the Somalia raid was in some ways the easier decision. “It’s less of a concern with the Somalia operation where there’s already this established infrastructure and a lot of cooperation on Al Shabab,” the administration official said. “Libya with a new, fragile government, the concerns were different and very real. We had to weigh what the risks and benefits are to doing this on the government, on the security situation for our people on the ground.”