Secretary of State John F. Kerry meets with Somali President Hassan Sheik Mohamud, center, and Prime Minister Omar Abdirashid Ali Sharmarke at the airport in Mogadishu. (Andrew Harnik/AP)

Secretary of State John F. Kerry made a surprise visit to Somalia on Tuesday, flying in to this capital city to show confidence in a country that not too long ago was a haven for militants and pirates.

Kerry, the first U.S. secretary of state to visit Somalia, spent a little more than three hours on the ground and never left the airport. He held meetings with the country’s president and prime minister, regional officials and civilian activists.

His presence was intended to send a message: that the United States is ready to reengage with the country 24 years after it closed its embassy. In 1993, Mogadishu became a symbol of the limits of a superpower when Somali militia fighters shot down two Black Hawk helicopters, killing 18 elite U.S. troops.

In a statement made just before departing, Kerry alluded to the U.S. withdrawal from Somalia and the ongoing concern about homegrown al-Shabab militants, who have staged attacks in neighboring nations and are linked to al-Qaeda.

“As everyone knows, more than 20 years ago the United States was forced to pull back from this country, and now we are returning in collaboration with the international community and with high hopes mixed, obviously, with ongoing concerns,” he said. “My brief visit confirms what diplomats have been telling me: The people here are both resilient and determined to reclaim their future from the terrorists and the militias who have been attempting to steal it.”

The Obama administration has nominated a new ambassador for Somalia. But in a sign of the continued security threats in Somalia, she will work out of the U.S. Embassy in Nairobi for the time being and make regular visits to Somalia.

Kerry’s visit was meant to draw attention to progress made in Somalia since 2012, when a new constitution was adopted, a parliament appointed and a president elected.

“It’s historic,” said a senior State Department official, briefing reporters on the condition of anonymity before Kerry’s visit, under agency rules. “I think it will send a strong signal to the Somali people of our commitment. And I think it will send a strong signal to al-Shabab that we are not turning our backs on the Somali people and that we will continue to engage with Somalia until we bring al-Shabab’s terror to an end.”

During the visit, Kerry invoked the Sept. 11, 2001, terrorist attacks on the United States and praised the five African nations that have sent peacekeeping troops to Somalia to help rout al-Shabab militants from most major cities and towns.

“We all have a stake in what happens here in Somalia,” Kerry said. “The world cannot afford to have places on the map that are essentially ungoverned. We learned in 2001 what happens when that is the case, and we have seen on a continued basis with splinter groups how they are determined to do injury to innocent people and to whole nations by operating out of ungoverned spaces.”

Kerry’s visit was planned in great secrecy for security reasons. President Hassan Sheik Mohamud and Prime Minister Omar Abdirashid Ali Sharmarke learned only recently that the secretary of state, not an undersecretary, would be visiting.

They and other Somali officials met with Kerry shortly after he arrived, a little before noon. He was driven to a one-story building on the airport grounds that was surrounded by reinforced seven-foot walls of sandbags.

They had a light exchange before the meeting officially began. The Somali president told Kerry that his visit was a “great moment” for Somalia.

“The next time I come, we have to be able to just walk downtown,” Kerry told him.

Mohamud told Kerry that Mogadishu has changed dramatically in the past two years.

“The roads are less bumpy, and we have traffic jams,” he said.

That means the country was “getting normal,” Kerry joked.

“Step by step,” he added.

Daud Aweis, a spokesman for the president, predicted that Kerry’s visit would resonate with everyday Somalis, particularly as the country prepares for elections next year.

“It’s a big thing to Somalis to have such a high-level delegation come at such a critical time,” he said.

The stop came one day after Kerry said the United States would provide an extra $45 million for the United Nations to help an overwhelmed Kenya cope with 600,000 refugees who have fled civil unrest, terrorism and violence in Somalia and South Sudan.

On Wednesday, Kerry heads to Djibouti, where the U.S. military has a hub from which it launches drone airstrikes on militants in Somalia. He is expected to express his gratitude to the Djibouti government for accepting thousands of refugees fleeing civil unrest in Yemen.

Read more:

America’s military hub for Africa

Danger in the skies in Djibouti