Joseph Walker-Cousins MBE is a former advisor to the UK’s Special Envoy & Head of the British Embassy Office in Benghazi (2011-2014) and Director, Middle East Business Development KBR UK Ltd. He is a global fellow at the Project for Study of the 21st Century.

Arriving in Benghazi by RAF military transport in May 2011 in the early days of the Libyan revolution, we never envisaged the aftermath of our intervention could be this bad.

Recent weeks have seen the gruesome murder of Egyptian Christian Copts and devastating suicide bombings (one last month in the eastern town of Qubbah killed 51 people and injured upwards of 80 more); all following the continuous discovery of countless headless security officials and the long list of murdered civil-society activists in Benghazi and Tripoli.

Central authority is crumbling and risks collapsing altogether. Amidst the confusion, extremist groups are proliferating; Islamic State has established an aggressive franchise, Egypt is conducting air-strikes against them, business is at a stand-still and the West has all but walked away.

Can it be turned around? I believe it can. But to do so, we must learn from our mistakes. Succeeding in Libya requires greater knowledge, determination, planning and overwhelmingly greater resources than our governments have so far devoted.

As in Iraq in 2003, we were led to believe by political émigrés back in Britain and elsewhere that Libya would be relatively simple, Muammar Gaddafi was finished, the army was useless and the tribes were broken. A new state was to be built on fresh and firm foundations. How mistaken we were to believe them.

During the early days of the rebellion, those who waved the black flag, then associated with al Qaeda, were a few hundred, fighting on the wings of the mixed civilian and military rebels and their foreign advisors. They have since expanded both in number and variety to include several other brand names including Islamic State.

Some of the Western advisors — both military and civilian — noted in private that, were these extremists only a few degrees longitude further to the east — in Afghanistan, say — we would be targeting them as opposed to coordinating with them.

Now they are in the ascendant. Following their losses in last year’s general election, an Islamist militia backed administration has seized power in Tripoli, displacing the elected Parliament to the easterly port city of Tobruk.

Libya’s official Army, Police and Oil Protection Forces have predominantly remained under Parliament’s authority while the less popular but increasingly better financed, armed and organized Islamist led militias have sided with the Muslim Brotherhood backed regime in Tripoli.

These Islamist groups are not content with just a share of the newly minted State, they want to own it entirely.

From the beginning, I and my superiors urged the National Transitional Council, which took power immediately after Gaddafi’s fall, to contain and counter these extremists. It was clear that they would expand, otherwise. They now number, including UN proscribed Ansar al-Shari’a, several thousand and are increasingly shaping and leading the fight against the elected authorities.

Initially, some in government, including civil rights lawyer and NTC spokeswoman Salwa Buqaiqis, viewed them as fellow revolutionaries fighting the tyrant. The week before her murder at their hands last June, however, Buqaiqis told me she had realised that they were a real existential threat to the country.

Former Libya PM Ali Zeidan with former US Secretary of State John Kerry and former British Foreign Secretary William Hague before his ousting in March 2014.

By last summer, Libyans were trying to resolve their differences by returning to the polls in an effort to correct an elected but broken congress. It had become partisan, an instrument of militias demanding a purge of the country’s previous officials. However, further to the east, a movement emerged, led by General Khalifah Hafter, which aimed to bring together what remained of the victorious army that had helped remove Gaddafi.

Those Libyan security forces had joined the broad-based revolt only to find themselves subsequently on the receiving end of an assassination campaign led by the Islamic extremists.

Buqaiqis told me one week before she was killed that she “hated the general, hated what he had stood for” as a former officer in the army under Gaddafi. However, he was now “the only hope” of containing the militias and extremists who, following their three consecutive losses in Libya’s general and constitutional elections, were now seeking power through force of the gun.

Hafter is not the man to lead the country; that must be done by the elected parliament and the government it appoints. However, the army and the police, who he is helping to corral still under the democratically appointed government, are the only organizations capable, with the right support, of containing and ultimately defeating the Islamist militants.

A unity government is the only internationally acceptable — or reasonable — way forward. That must mean a common purpose: most pressingly, the defeat of the Islamic State, re-establishing law and order and salvaging the economy.

This is something the Parliament in Tobruk could deliver but the Muslim Brotherhood-backed administration in Tripoli is incapable of doing, preferring to condemn the Egyptian strikes that targeted Islamic State.

At present, outside involvement in Libya risks making it ever more fragmented. Egypt’s military rulers hate the Brotherhood almost as much as IS. Other regional states, however, particularly Qatar, take a rather different approach. The West, meanwhile, simply wrings its hands.

We need to change course on Libya and more tangibly back the democratically elected legitimate authorities. And we must free the Libyans’ hands to solve their own problems by allowing them access to their own resources and supporting the resumption of oil production to source arms and outside expertise.

There are complexities. The tribal militias in the coastal town of Misrata, for example, have sided with the Islamists in part over concerns over other ethnic groups. But they could be won back.

We don’t need foreign boots on the ground. As a senior tribal figure and leading Army officer fighting more heavily armed and better financed extremists in the East told us in 2013, we should just “give them the tools, they would finish the job.”