There has been largely unexpected good news from the embattled country: an election that was regarded as (mostly) free and fair led to the first democratic transfer of power in its history when the former military dictator Muhammadu Buhari beat the incumbent, Goodluck Jonathan, by 15.4m votes to 12.9m.

One could almost hear the collective sigh of relief when Jonathan conceded defeat and urged supporters of his People’s Democratic Party (PDP) to accept the decision of the Independent National Electoral Commission (INEC) that Buhari had won, despite combustible allegations of irregularities at the polls. The spectre of violence sweeping the country as it had after the 2011 elections, when 800 people died, faded.

Buhari has asserted his democratic credentials (such as at Chatham House, when he declared: ‘Before you is a former military ruler and a converted democrat who is ready to operate under democratic norms’). There was praise for Jonathan, who prevented the polls becoming the habitual vote-rigging exercise (‘I promised the country free and fair elections. I have kept my word,’ he said), and Attahiru Jega, head of the INEC, for his tough-minded determination to oversee a credible vote.

In a statement issued after the results were announced, Jonathan declared: ‘I urge those who may feel aggrieved to follow due process, based on our constitution and our electoral laws, in seeking redress. Nobody’s ambition is worth the blood of any Nigerian. The unity, stability and progress of our dear country is more important than anything else.’

It could be said that Jonathan’s finest moment as president came in relinquishing power. Certainly, his record in office was abysmal, even by the low standards of Nigerian presidents. About half the population still live below the poverty line, corruption on a vast scale continued unabated under his watch (the equivalent of 100,000 barrels of oil a day are stolen, according to the Economist), education was neglected (at 51%, according to Unicef and theCIA, literacy rates are nearly half that of South Africa, though it recently overtook that country in terms of GDP), the power network would be inadequate for a far smaller and poorer country, and the military—supposedly one of the strongest in Africa—is so under-equipped that soldiers go unpaid, often lack tents or bedding, and must scavenge for fuel.

This last problem is part of the explanation for Jonathan’s greatest failing: that he allowed Boko Haram to grow almost unchecked from a small, isolated and ineffective protest movement to grow almost unchecked into an insurgency that threatens the entire region and is plugged into the jihadi network of Islamic State (swearing itsallegiance to Isis in March). After Jonathan declared a state of emergency in May 2013 the number of civilian deaths rose, according to the BBC. In 2014 Boko Haram controlled an area larger than Belgium, Luxembourg, and the Netherlands across three north-eastern Nigerian states and parts of adjoining countries, and had slaughtered at least 5,500 civilians and abducted at least 2,000 women and girls, according to Amnesty International. The cumulative total since 2011 had reached a ghastly 37,650, the Council on Foreign Relations said.

And yet here too there is room for cautious optimism. The combined forces of Nigeria, Cameroon, Chad, Niger and Benin, with support from the US and France’s 3,000-strong Sahel counter-insurgency force (until recently focused on Islamist militants in Mali and Chad) have begun to turn the tide of the Boko Haram insurgency. In May the fightback bore fruit with the rescue of hundreds of women and children held captive in a series of setbacks for the rebels as Nigerian troops assaulted Boko Haram’s hideouts in the Sambisa forest, near the Cameroon border.

Washington was reluctant to get embroiled in more foreign firefighting but as Boko Haram’s scorched-earth massacres pushed it to the top of the global jihadi league table by 2014, and the insurgency spilled over Nigeria’s borders to threaten Cameroon, Chad and Niger, the US military rethought its regional strategy and three months ago decided it was ‘ready to assist in whatever way [Nigeria] sees as being practical’, according to Lt Gen Steven Hummer, of US Africa Command. This largely took the form of surveillance flights and sharing intelligence, and while Nigeria’s ambassador appealed for more direct support it did mark a turning point in the fight against the jihadis. Similarly, in a development that Jonathan’s government understandably kept quiet about, South African mercenaries were hired to add some bush warfare competence to the campaign.

But as the New York Times reported, Chadian troops have liberated towns with no Nigerian soldiers to be seen. A Cameroonian officer told the Guardian: ‘I have no faith in Nigeria—neither the government nor the army. If things are calmer it’s not because of what the Nigerian army has done but because the Chadian forces have absorbed the intensity of the fight.’

Colonel Jacob Kodji, Cameroon’s regional commander, said: ‘We don’t understand why the rest of the world hasn’t helped us more. We need help from developed countries. You can see everything from your satellites, but we can’t place a soldier every few metres along a 400​km-long border.’

And as Channel 4’s Lindsay Hilsum points out, many villagers in the affected region are in an impossible bind: suspected of harbouring Boko Haram by the various military and punished for suspected collaboration with the authorities by the Islamists.

Buhari is the man to defeat Boko Haram, the journal Foreign Policy declared. But there is a long way to go yet before the many thousands of refugees in this region will sleep easily.