By all reasonable precedents the United States of America and other nations of the world should recognize Shabab (aka Al-Shabaab) and its allies as the de facto government of Somalia.
Shabab is labeled as a terrorist group by the US. Big deal. Allies of the U.S. who use armed force to create governments are labeled freedom fighters; any group not allied with the U.S. that uses armed force gets the terrorist label. Let's look past the propaganda and consider the reality.
The U.S. has tried to install a variety of governments in Somalia over the past two decades, using force and economic aid. That is more than terrorism: that constitutes war crimes. Every attempt to install a pro-U.S. government has failed, including the U.S. financed invasion by Ethiopia in 2006 (major war crime authorized by President George W. Bush).
The recognition of de facto governments is an ancient and almost universal practice. One nation is not obliged to like another nation. Diplomatic recognition is a pragmatic affair. It does not involve an alliance with the nation or government recognized.
The United States of America has a bit more of an uncivilized, brutal history in this regard than the more civilized nations. Most notably, the U.S. failed to recognize the government of China from 1950 until 1972.
On the other hand, the United States has not only recognized, but has propped up, a wide variety of unsavory regimes over the centuries. At first these tended to be South American kleptocrats allied with American business interests. Later, during the cold war, they included any brutal but aspiring military officer who promised to kill communists, socialists, democrats and freedom of speech in general. In other words, neither lack of elections nor brutality precluded American recognition of governments — as long as they were our governments.
There are dangers to leaving the Somalis to themselves, but they are outweighed by the advantages and the likely cultural trajectory. When idealistic groups like Shabab come to power they usually start off with a puritanical regimen. Their subjects will pretend to also have become puritans, if only to escape punishment. But having achieved power, the leaders will begin to relax over time. With an orderly regime trade and industry will pick up again, and Shabab will start growing fat on taxing that. In other words, after 10 years or so they won't be much different than any other government. They are unlikely to develop a military that can successfully invade their neighbors. Somalia has neither the wealth nor the industrial base for that sort of thing.
There are so many examples of this in history, let me remind you of a couple. In the American Revolution terrorist tactics were used against the pro-British Tories. But as soon as Washington & crew were accepted by the international community they calmed down and lived peacefully happily ever after. Except for attacks on American Indians. And the attempt to conquer Canada in 1812. And grabbing half of Mexico in 1848. Well, maybe the U.S. is not such a great example.
But we could always declare war on Somalia later, or engage in yet another undeclared war. Right now the best way to relieve the suffering in Somalia is to withdraw African Union troops, recognize the de facto governance by Islamic fighters, and leave them to stew among themselves. Maybe even Shabab won't be able to govern Somalia. But if, say, the Saudis offered to build a mosque or two to celebrate the great Islamic victory, and threw in some luxury snacks and free trips to Mecca, pretty soon the government of Somalia would not look very different than any other government. Meddlesome and incompetent, but slightly better than living in an ongoing civil war.