Anthony Banbury is the United Nations’ assistant secretary general for field support.

Walking through Mogadishu recently, I couldn’t help but marvel. The streets teemed with people going about their daily lives. Construction boomed on virtually every block, fueled by investments from the Somali diaspora (and, perhaps, from pirates’ ill-gotten gains). Police officers in crisp white shirts directed traffic — a phenomenon associated with a return to normality in many post-conflict areas — and workers repaired electrical lines.

Spend an hour talking to Hassan Sheik Mohamud, the longtime educator and civil activist recently elected president, and you begin to believe that Somalia is on the path to a brighter future.

Many may recall the 1991 overthrow and subsequent assassination of Somalia’s former president, Mohamed Siad Barre, which plunged the country into civil war and then anarchy. The United States and the United Nations deployed forces to help bring some stability and stem a famine. These efforts brought rapid improvement in the humanitarian situation but also the “Black Hawk Down” incident of October 1993, when 18 U.S. soldiers were killed. Less remembered are the hundreds of Somalis and 160 U.N. peacekeepers who also died during the Somali conflict. The United States and the United Nations decided to withdraw their forces, leaving Somalis to confront the future on their own.

Well, not exactly.

The United Nations never left Somalia. Despite the disastrous situation, U.N. personnel have remained engaged, providing assistance as security conditions and donor funding have allowed, risking their freedom and often their lives. Somalia has not had a functioning government since 1991. Only 25 percent of Somali children attend school. Instead, boys join militias and learn how to kill. Most Somalis in their early 20s have never experienced any form of governance, have never seen a college and or even had regular electricity. Pirates maraud on land as well as sea, without fear of arrest. Foreign terrorists rally the disenchanted to their cause. There has been endless fighting, with the conflict transforming from a civil war to warlordism and then to religious extremists vying for power, all at the expense of ordinary Somalis.

For too long, there seemed scant hope of Somalia extricating itself from this morass. But the situation has changed.

The African Union, led by Uganda and Burundi and later joined by Kenya, sent a force to combat the extremist al-Shabab militia, a group linked with al-Qaeda. With extensive U.N. logistical support and considerable sacrifices, the African Union Mission in Somalia (known as AMISOM) fought long and hard to dislodge al-Shabab from Mogadishu. Al-Shabab is also on the run in central and southern Somalia, where it has long dominated. Just this month its members were expelled from their last stronghold, the port city of Kismayo, in a joint operation by Somali and AMISOM forces, led by Kenya.

Meanwhile, Somalia’s political and clan leaders have engaged in the transition from a tenuous, transitional government to a newly elected parliament and president — the country’s first peaceful handover of power to an elected president in decades. The dramatic contemporaneous developments in the fighting and the political arena present the best potential for peace in Somalia since 1991.

Getting to this point has been difficult and costly in terms of lives lost, human suffering and resources expended.

The United Nations is often criticized for a raft of alleged shortcomings. I wish these critics would go to Somalia and spend time with folks like our chief engineer in Mogadishu, a Turkish woman who works endless hours to build facilities for U.N. civilian employees and African Union soldiers.

The United Nations’ work in Somalia is an example of the organization at its best — years of dogged engagement, out of sight of most of the world, in solidarity with the country’s citizens, often at great risk to U.N. staff.

The U.N. presence in Somalia has often made lifesaving differences. This assistance ramped up after U.N. Secretary General Ban Ki-Moon visited Mogadishu in December and instructed his special representative for Somalia, Augustine Mahiga, and others based in Nairobi to move to Mogadishu in January. Mahiga and his team played a crucial role facilitating the political dialogue that led to the peaceful transition of government.

Because of the work and sacrifices by the United Nations, the African Union and other key stakeholders, and most of all because of the Somali people’s struggles, Somalia has a chance for a decent future.

Any alternative is just not acceptable.

As President Mohamud told me, Somalia has lost two generations; failure is not an option. At this moment of great opportunity, the world must stand by the long-suffering people of Somalia. While the future is unclear, one thing Somalis can count on is that, as in the past, the United Nations will be with them as they pursue peace and development.