Nigerian president Muhammadu Buhari has replaced the four heads of the country’s armed forces after years of resisting widespread calls to do so, in a belated acknowledgment of the swiftly deteriorating security situation in Africa’s most populous country.

Mr Buhari had refused to heed calls from critics and supporters alike to dismiss the heads of the army, navy and air force and chief of defence staff, all of whom he had first appointed in 2015 when he was swept into office on a pledge to crush the Boko Haram jihadist insurgency.

In a message on Twitter on Tuesday, Mr Buhari said he had accepted resignations from the four men and thanked the officers for “their overwhelming achievements in our efforts at bringing enduring peace to Nigeria”.

Mr Buhari and his government have long argued that Boko Haram has been “technically defeated” and that the security situation has improved under his watch. But six years into his tenure, the jihadist group continues to kill soldiers and civilians in the north-east with impunity, while roving gangs of armed bandits terrorise highways and villages across the country and the Gulf of Guinea has become the world’s most dangerous shipping zone. Large parts of the country, particularly in the north-east and north-west, are outside of government control.

The senate, which is led by Mr Buhari’s party, passed three bills last year calling on the president to sack the armed forces chiefs. But Mr Buhari resisted until Tuesday. He did not explain why he accepted their resignations.

Cheta Nwanze, partner at Lagos-based consultancy SBM Intelligence, said the move was “long overdue”.

“When [the service chiefs] came in, we only had ‘open warfare’ in two of Nigeria's regions,” he said. “Now we have [it] in all six, and the army is deployed on operations in 35 of the 36 states.”

The move comes about a month after armed bandits brazenly kidnapped hundreds of schoolboys in Mr Buhari’s home state while he was there on holiday. The bandit crisis has made major highways across Nigeria, including the one linking the capital Abuja to northern Kaduna state, all but unpassable. Newspapers are regularly filled with stories about dozens of people being killed in attacks on villages in every corner of the country. According to the International Crisis Group, more than 200,000 people have been displaced by banditry in the country’s north-west alone.

Meanwhile, Nigerian pirates have turned the Gulf of Guinea into a global hotspot for piracy. Last year, 130 sailors were kidnapped in 22 incidents — only five were kidnapped anywhere else in the world, according to data from the International Maritime Bureau. The pirates generally come from the oil-rich Niger delta, where they once made their money stealing crude.

Nigeria recently entered its second recession in five years, and the security situation is expected to deteriorate further as unemployment and inflation rise further.

Tanwa Ashiru, founder of Lagos-based risk consultancy Bulwark Intelligence, said she doubted new military leadership will change that downward trajectory. “The Buhari administration puts too much emphasis on the military in securing the nation, but this has not worked,” she said. “Nigeria’s security problems need to be tackled on a local/tribal level” through local leaders, development and community policing.

Mr Buhari named Major General Leo Irabor as chief of defence staff; Rear Admiral AZ Gambo as chief of naval staff; Air-Vice Marshal IO Amao as chief of air staff and Major General I Attahiru as chief of army staff.