GUNFIRE pierced the night quiet. For weeks, inhabitants of the ancient desert towns of Gao and Timbuktu had feared that rival Tuareg rebels would clash. Between January and March they had together waged a devastatingly effective campaign against Mali's army, sending its last troops packing in early April and proclaiming an independent state called Azawad. But the rivalry then flared, and lawlessness and factionalism have been rife since. Machinegun bursts on May 26th sent residents scurrying for cover. But the shooting turned out to be celebratory. The National Movement for the Liberation of Azawad, a secular group known by its French initials, MNLA, had cut a deal with Islamic fundamentalists from a locally dominant lot called Ansar Eddine. The pair agreed to join forces and set up a transitional government. Peace would follow. Yet residents still have reason to be scared. Ansar Eddine has become almost indistinguishable from al-Qaeda in the Islamic Maghreb (AQIM). This is the closest to government that al-Qaeda, under any guise, has ever come. Though the nomadic Tuareg and other ethnic groups of northern Mali number only 1.3m people, the area they now control is as big as France. The new alliance seems to be founded on two pillars. Ansar Eddine, which had previously argued only for autonomy, has evidently dropped its objections to full independence. And the MNLA has agreed to an Islamic state. Many MNLA supporters are aghast at what they see as a betrayal of a core principle of the decades-old Tuareg rebellion: a secular state offering freedom of religion and lifestyle.

The deal may yet fall apart. Tuareg officials say they want a model “similar to Mauritania or even Egypt”, where state and religion have rarely mixed. Ansar Eddine insists on a strict interpretation of sharia law, with amputations and beheadings for serious crimes. The two sides also argue over the government's make-up. Such is the mistrust that the MNLA leaders refused to let Ansar Eddine's leader, a notoriously tricky strongman called Iyad ag Ghali, sign an earlier accord.

In the end a tribal chief close to him had to put his name to it. The MNLA chose to deal with Ansar Eddine because the fundamentalists have money and guns, whereas the MNLA can barely afford to pay salaries. Flush with cash from al-Qaeda, Mr ag Ghali has started to attract deserters from the impecunious Tuareg.

The government in Bamako, Mali's capital, is in disarray after a coup by disaffected soldiers in March and is struggling to control even the southern half of the country, having abandoned the north to the assorted rebels. Meanwhile the MNLA naively thought that, as long as it distanced itself from AQIM, the West would support it. Instead it has been outmanoeuvred by Ansar Eddine. The West, with France to the fore, is hardly likely to tolerate the existence of an al-Qaeda-run state in a large swathe of west Africa.