It’s easy to characterise the war in Mali as a simple battle between brutal Islamic fundamentalists who want to force sharia on an unwilling populace and French forces lending support to a weak but benign Malian army and government.
Reality, of course, is a little more complex. Ethnic divisions in Malian society are also important, and the war is partly the result of a corrupt state and predatory military.Northern Mali has been unstable since the early 2000s, when Algerian jihadis were defeated in that country’s decade-long civil war and moved south across the border. The vast, poorly governed desert area proved a profitable place for them. They ran a lucrative trade smuggling cigarettes, arms and drugs. When they began to kidnap western tourists and workers, European governments asked the Malian government to help negotiate the hostages’ release. Millions of euros were agreed as ransoms, and Malian officials creamed off a percentage for themselves. The hostages were released, the Malian government became even more corrupt than it was before, and the jihadis grew rich.

Northern Mali is home to the nomadic Tuareg people, who are sometimes called the Kurds of Africa, as they are spread across six countries – Libya, Algeria, Niger, Mali, Morocco and Burkina Faso – with no state of their own. They have many grievances, including poverty and lack of development, so since Mali’s independence from France, there have been several Tuareg uprisings. Many Tuareg were recruited into Colonel Gaddafi’s army in Libya – after his death,  a contingent returned to Mali carrying weapons he had given them. In January 2012 they mounted an uprising for an independent Tuareg state – Azawad. They called themselves the National Movement for the Liberation of Azawad (MNLA).

The Malian army had been trained and to some extent equipped by the Americans as part of an anti-terrorism programme. However, they were no match for the MNLA. Poor logistics meant they were often hungry; corruption meant that money which should have been spent on weapons disappeared into the pockets of politicians. On 24 January, militants, believed to be from Islamist groups fighting alongside the MNLA, slit the throats of 82 Malian soldiers at Aguelhok. Some, probably most, Tuareg officers had already deserted and joined the MNLA. The rest of the soldiers turned tail and ran south.

Back in the Malian capital, Bamako, junior officers grew angry. Some hadn’t been paid for months. Their wives demonstrated. On 22 March 2012, a certain Captain Amadou Sanogo stormed into the office of President Amadou Toumani Traore, who fled into exile. It was an old-fashioned African coup. But the world has changed since the 1970s and 80s when military juntas were common. Neither West African governments nor western donor countries would accept military rule in Mali. So a new government was put in place, which many saw just as a civilian facade – it was an open secret that Captain Sanogo still held ultimate power.  There was talk of military intervention by West African states, but while the captain was happy for soldiers of other nationalities to do the Malians’ fighting for them in the north, he didn’t like the first part of the plan – stabilising civilian rule in Bamako – because he would be sidelined.

23 mali r w What you to need to know about Mali   a beginners guide

Back in the north, some MNLA joined up with the jihadis – the largely Algerian al-Qaeda in the Islamic Mahgreb (AQIM), the mainly Malian Ansar Dine (“Defenders of the Faith”) and the Movement for Jihad and Unity (MUJAO). On the night of 30 March 2012 a column of Ansar Dine, AQIM and MNLA rolled into Timbuktu in armoured vehicles which the Malian army had left behind – most had been a gift of the USA.

Instead of trying to govern effectively, the MNLA embarked on a chaotic campaign of plunder and rape. I have met nurses who describe caring for girls who were gang-raped by the MNLA in Timbuktu, Gao and other towns. They gained a reputation for terror amongst non-Tuareg in the area. After a while, the jihadis started to fight the MNLA and many people were not upset when the jihadis took over in Timbuktu, Gao and Kidal – at least, they thought, the Islamists would bring law and order.

And indeed they did – but not the kind of law and order Malians were used to. They flogged anyone who smoked, stoned suspected adulterers to death and cut off the hands of alleged thieves. In Timbuktu, Ansar Dine took pick-axes to ancient mud shrines, saying they were idolatrous. Some Malians say that an ethnic element has surfaced in the north, that the jihadis are primarily Arabs and Tuareg, as well as foreigners, and they target black Malians. In the south, some black Malians and soldiers attacked Tuareg whom they blamed for sowing chaos in the country. Half a million people fled the north, most for other parts of Mali, but 150,000 – mainly Tuareg – for neighbouring countries.

The jihadis now controlled three airports and several large towns and enjoyed free movement in the desert. They had gained what they had lost in Afghanistan in 2011: “Dar al Islam”, an Islamic land in which they could welcome international Islamist fighters and from which they could mount attacks anywhere. That was the state of Mali until the French intervened. The country was divided between the north, which was ruled by the jihadis, and the south governed by a supposedly civilian government but really by a junior officer and a small clique around him. The MNLA was in disarray. The UN approved the West African intervention force, but it was not expected to be ready before September 2012. Then, in early January 2013, the jihadis began their move south, potentially threatening the capital, Bamako. The French mounted their first airstrikes on 11 January 2013.

The political class in Bamako squabbles as if there was no crisis. The army remains weak and ill-disciplined – Malians I’ve met say they have no trust in their soldiers. The French have been welcomed, but we’ve seen this before: those regarded as liberators one day are occupiers the next. It’s not just a question of defeating jihadis, but of recreating Mali as a functioning, unitary state. That will take years.

You can follow @lindseyhilsum on Twitter