The fact that Mogadishu has turned to the US, of all countries, for assistance in combatting extremists is just another example of America's desire for regional dominance. It's certainly no coincidence that Washington decided in May to redeploy troops to Somalia under the guise of "fighting terrorism." In reality, Washington is primarily concerned with containing the growing influence of China, but also Russia, in this strategically important region.
After former Pres. Trump decided to withdraw US troops from Somalia, there was an uptick in terrorist violence. The fact that the Somali federal government is now making progress against terrorists is due to the return of US troops to the country and America's military cooperation with Mogadishu. Since al-Shabaab and IS also pose a direct threat to the US itself, defeating these terrorists is also a matter of national security.