Nicholas Haysom, then the top U.N. envoy in Afghanistan, speaks during a news conference in Kabul in 2015. (Massoud Hossaini/AP)

Somalia’s government took the unusually drastic step of expelling the United Nations’ most senior official in the country late Tuesday after he questioned the detention of a former al-Shabab leader contesting regional elections.

Nicholas Haysom, a South African, had served only a few months as the special representative for U.N. Secretary General António Guterres. Somalia’s Foreign Ministry declared him “persona non grata” and ordered him to leave the country.

“The decision came after the highest U.N. diplomat in Somalia violated the agency’s standards and the international diplomatic norms by intervening in the national sovereignty of Somalia,” the Foreign Ministry said in a statement published by state-owned media.

Haysom’s expulsion comes amid a political crisis that has pitted the governments of Somalia’s semiautonomous regions against the federal government based in the capital, Mogadishu. The regional governments are in the process of holding elections.

In the South West state, the only one that has held its election so far, the favorite candidate to win the top leadership position was Mukhtar Robow, who had served as the deputy leader of the Islamist militant group al-Shabab for many years before defecting in 2017. Robow was barred by the federal government from running, ostensibly for his failure to formally repudiate al-Shabab.

Robow’s defection was originally seen as a major win for the government, which is trying to encourage such defections, but his bid for elective office was clearly not what authorities had in mind.

He was arrested by police days before the election. Subsequent rioting by his supporters in the regional capital, Baidoa, resulted in at least 15 deaths, and scores were detained by security forces. Robow was transferred to a prison run by Somalia’s intelligence service in Mogadishu.

In a letter to the federal government, Haysom criticized the crackdown and questioned the legal basis for holding Robow without charge beyond a 48-hour limit.

The letter also highlighted civilian deaths during the protests and said they must be “thoroughly and promptly investigated.” Haysom wrote that more than 300 people, including minors, were arrested after the demonstrations in Baidoa.

Paul Williams, the author of a book on peacekeeping in Somalia and a professor at George Washington University, warned the move will only benefit al-Shabab.

“The move signals that the federal government isn’t willing to be transparent on key issues of defection programs or engage in dialogue on controversial issues,” he said, adding al-Shabab can now say “the federal government is breaking its own domestic laws and the U.N. is interfering with Somalia’s domestic affairs.”

Al-Shabab once controlled most of southern Somalia, but most cities have been taken back by an African Union-led force that is about 20,000 strong. In the mostly rural areas it now controls, the al-Qaeda-aligned group imposes a strict version of Islamic law.

It has carried out countless kidnappings and suicide bombings in the country over the past decade.

The United States is a close backer of Somalia’s federal government and has largely refrained from criticizing it, though it did sign on to a letter expressing concern over Robow’s arrest and the subsequent crackdown.

There are 500 U.S. troops in the country, mostly Special Operations forces, assigned to train Somali soldiers. The United States also carries out frequent airstrikes against al-Shabab, most recently in December, when 62 fighters were killed.