The raid by Navy SEALs on a Somali villa in search of a senior Al-Shabab commander (his fate is unknown) and the capture by American commandos of a key terrorist suspect in Libya were signs of a more assertive American role in trying to curb rising militancy and terrorist enclaves in North Africa.

Somalia, which had no central government for two decades, has long been a haven for terrorists, though there was some limited improvement in its political system earlier this year.

But the terrorist attack on an upscale mall in Kenya last month has revived fears about Somalia’s homegrown Al-Qaida-linked extremists known as Al-Shabab, which claimed responsibility.

The militants have threatened to intensify attacks on Kenya until Kenyan troops that are part of an African Union mission leave Somalia. That mission, authorized by the United Nations, is backed by American drone and aircraft strikes on targeted militant leaders. Over the last six years, the U.S. government has provided hundreds of millions of dollars in military, humanitarian and development aid.

This support has enabled the African Union force, working with Somali Army units, to push Al-Shabab out of the capital, Mogadishu, and has given officials there a chance to govern.

Military action alone won’t do the job, however. Al-Shabab maintains support among some Somalians by presenting itself as protecting their country from predatory foreign forces. Countries with a stake in a more stable Somalia have to do a better job of counteracting that claim. Kenya, for instance, can help by ending abuses by its security forces in the African Union mission and its domestic police force against Somalis who do not support Al-Shabab.

The fact is, Kenya has been hostage to the decades-long collapse and lawlessness of Somalia, which sits on its border. But the government in Nairobi should not use the attack as a reason to close refugee camps in Kenya that house hundreds of thousands of Somalis or take other steps to indiscriminately crack down on Somalis in the country.

The mall assault showed new desperation by Al Shabab. With these kinds of looming threats, the Obama administration should increase its efforts to cut off financing for Al Shabab, including fundraising in the United States.

Rumors that Americans were among the mall attackers have not been proved, but in recent years several Somali-Americans have been prosecuted for terrorist financing and indicted on suspicion of traveling to fight with Al Shabab. A Congressional Research Service report said more than 20 young men from Minnesota have gone to fight in Somalia.

The mall attack has demonstrated that Al Shabab remains a resilient and lethal adversary. Regional stability in North Africa will depend on the United States, Kenya and other partners finding effective ways to contain it.