Kenya has said it is withdrawing its troops from the United Nations mission in South Sudan, a day after Ban Ki-moon sacked the Kenyan commander of peacekeeping forces in the country for failing to protect civilians.

In an angrily worded statement, the Kenyan ministry of foreign affairs said on Wednesday that it was “dismayed” by the UN secretary-general’s decision to dismiss Lieutenant General Johnson Mogoa Kimani Ondieki.

Continued deployment of Kenyan troops in South Sudan “is no longer tenable”, the ministry said, saying Kenya would “withdraw, immediately” its forces there.

Kenya has more than 1,000 troops deployed in South Sudan.

The ministry said the UN mission in the country, known as UNMISS, suffered from “systemic dysfunctionality” and that Ondieki was not to blame for violence that killed dozens of people.

“What is clear is that UNMISS suffers from fundamental structural and systemic dysfunctionality, which has severely hindered its ability to discharge its mandate since its inception,” it said.

“Regretably, instead of addressing these shortcomings directly, the United Nations has instead opted to unfairly attribute them to a single individual, in the name of the Lieutenant General Ondieki.

A special UN investigation released on Tuesday blamed Ondieki and a “lack of leadership” in UNMISS for the “chaotic and ineffective response” to the violence in the capital Juba in July.

The damning report also accused UN peacekeepers of abandoning their posts and failing to respond to pleas for help from aid workers under attack in the Terrain Hotel, less than a mile from a UN compound.

Dozens of people were killed between July 8 to 11, and at least five foreign aid workers were raped when between 80 and 100 uniformed soldiers overran the hotel.

In the weeks following the violence, UNMISS also struggled to send out armoured or foot patrols. During this period, large numbers of South Sudanese women were raped by soldiers from President Salva Kiir’s Sudan People’s Liberation Army (SPLA).

In September, following the threat of an arms embargo, South Sudan agreed to allow 4,000 additional UN peacekeepers to enter the country, after first rejecting the regional protection force as a breach of national sovereignty.

READ MORE: The UN has failed its peacekeepers in S Sudan

Thousands of UN peacekeepers have been deployed to South Sudan since the country gained independence from Sudan in 2011.

A political rivalry between Kiir and his former deputy Riek Machar sparked a civil war in 2013, when the president accused Machar of plotting a coup.

Since then, tens of thousands of people have died in the conflict and hundreds of thousands have been left without food.

The rivals signed a peace agreement late last year, under which Machar was once again made vice president, but renewed fighting has seen Machar go into hiding, and a member of his opposition – Taban Deng Gai – take his place as First Vice President.