Secretary of State John Kerry made an unannounced trip to Somalia Tuesday in a show of solidarity with a government trying to defeat Al Qaeda-allied militants and end decades of war in the African country.  He is first top U.S. diplomat ever to visit Somalia.

Kerry arrived at Mogadishu's airport around noon local time (5 a.m. ET) and immediately entered a series of planned meetings that include Somalia's president, prime minister and regional leaders, and civil society groups.

The trip was made under tight security conditions. Somalia's government only found out a day ago that Kerry would join the State Department's top Africa official, Linda Greenfield-Thomas, on the voyage. And the fact that he was only dipping his toe in Somalia, and not venturing past the airport, highlighted just how dangerous and instable the country remains.

Top of the agenda is the fight against al-Shabab. African forces and U.S. drone strikes have crippled the organization's leadership in recent years and left the extremists without much of the territory they once controlled or the cash flows needed to reverse their losses.

But as al-Shabab has decentralized, the militants in some ways have become even more dangerous, expanding their activities in Kenya and other neighboring countries. Last month's massacre at Kenya's Garissa University College killed 148 people, mostly students, and underscored the group's capacity to carry out relatively unsophisticated but extremely deadly terrorist attacks far from its bases of operations.

Kerry's presence in Somalia "will send a strong signal to al-Shabab that we are not turning our backs on the Somali people," said a senior State Department official, explaining the purpose of the visit. "We will continue to engage with Somalia until we bring al-Shabab's terror to an end," added the official, who wasn't authorized to speak publicly about the trip and demanded anonymity.

Somalia has been without a truly functioning government for two-and-a-half decades. After warlords ousted dictator Siad Barre from power in 1991, they quickly turned on one another and plunged the country into anarchy. Militias, Islamist extremist groups and Somalia's nominally national military all vied for power before the tide turned against al-Shabab earlier this decade. Piracy also has been a major problem.

Yet even as a relative calm has settled over parts of the country, including Mogadishu, Somalia remains fraught with a painful history for the United States.

American troops were sent there in 1992 on a peacekeeping mission to help stave off a national famine. They left two years later in humiliation after the "Black Hawk Down" debacle when Somali militiamen shot down two U.S. helicopters. Eighteen servicemen were killed in the crash and subsequent rescue attempt, the indelible memory being the images of American bodies dragged through Somalia's streets.

The Obama administration is banking on President Hassan Sheikh Mohamud's government to turn a new page toward democracy and economic development. The U.S. has provided hundreds of millions in military support to build up and professionalize the army, and is working with Mohamud to try to usher in a broader, more representative government over the next 18 months.

If that effort is successful and stability expands, officials say the U.S. could re-establish an American embassy in the capital before President Barack Obama leaves office. For now, the president has nominated a career diplomat, Katherine Dhanani, to serve as the first U.S. ambassador to the country since 1991, with the idea that she would operate out of Nairobi and make regular trips into Somalia.

Britain, Italy and several other countries already have embassies in Mogadishu.

Kerry's brief foray comes a day after extensive counterterrorism and refugee talks with Kenya's government, much of it deeply tied to the situation north of the border. For the Kenyans, stability in Somalia can't come soon enough. They are scrambling to combat al-Shabab and even have threatened to begin emptying the sprawling Dadaab refugee camp, the world's largest with some 350,000 Somali inhabitants.

Kerry said he received assurances from President Uhuru Kenyatta that no unilateral action would take place to close Dadaab as the U.S. and others try to make Somalia safe enough to accommodate large-scale refugee returns.

Their discussions came as the region's refugee crisis becomes increasingly complex, with war in nearby Yemen creating conditions so dire that some people are even fleeing to Somalia.

Aid agencies are undertaking contingency planning for a prolonged conflict in Yemen that could prompt 100,000 people to escape across the Gulf of Aden to Somalia and 30,000 to Djibouti this year. It's unclear how Somalia, in particular, would be able to handle such an influx given its persistently high levels of violence.