THE murder of Christopher Stevens, the American ambassador to Libya, along with three of his colleagues at his consulate in Benghazi, Libya’s second city, was not an isolated instance of violence directed against Westerners since the fall of Muammar Qaddafi’s regime nearly a year ago. In the past few months the British ambassador’s convoy on a visit to Benghazi has been attacked. So have the offices of the Red Cross and the UN in that city, the cradle of the Libyan revolution. The perpetrators of all those crimes were thought to be Salafists espousing an extreme fundamentalist version of Islam that harks back to the days of the Prophet Muhammad.

In the past few weeks Salafists have also attacked shrines in Tripoli, the capital, and elsewhere in Libya that have been venerated for centuries by Sufis, who practise a mystical form of Islam that many puritans consider idolatrous. One such shrine, honouring al-Shaab al-Dahmani, was in full view of the Radisson Blu Hotel, a favourite venue for visiting foreign bigwigs and prominent Libyans. What astonished them was that the destroyers of the shrine were allowed, over a period of 48 hours, to pillage and bulldoze the site without the ministry of interior or its police apparently lifting a finger to stop them.

This suggests either that the extreme Islamists typified by the Salafists have friends in high places protecting them or that the government and its security arm, however well-intentioned, is too feeble or disorganised to deal robustly with them. Either way, it is unlikely to encourage investment or reassure sceptics that security in the country is under control.

Indeed, a further disquieting aspect of the new Libya is the continuing ability of local militias, especially in places such as Misrata and Zintan that bore the burden of the battle against Qaddafi, to ignore the writ of the central government. Moreover, tribal and ethnic tensions on the fringes of the country and in remote southern cities such as Sebha and Kufra, continue to provoke periodic outbreaks of violence that stir bad blood and deter investors.

Yet there has also been remarkable progress, especially on the political front, in the months since the death of Qaddafi on October 20th. On September 12th the newly elected General National Congress, a proto-parliament, elected Mustafa Abushagur, a secular-minded electrical-engineering professor previously based in California who had been in exile for 31 years, as prime minister. He is expected in a few weeks to appoint Libya’s first-ever democratically chosen government. Another body will write a constitution. A full-fledged parliament is to be elected within 18 months. These steady advances have been achieved with surprisingly little discord and much satisfaction after decades of tyranny. The mood in the country is still overwhelmingly hopeful.

The most striking outcome of the congressional election in July was the relative failure of the Islamists, whose main party, Justice and Construction, allied to the Muslim Brotherhood, got only 17 out of the 80 seats elected by proportional representation on party lists, whereas a coalition of secularists, liberals and milder Islamists won 39. An Islamist party including Abdel Hakim Belhaj that was lavishly financed by Qatar got no seats at all. It may, however, take a while to identify the congress’s overall ideological hue because 120 of its 200 members are independents elected on individual slates, usually without advertising a religious or informal party affiliation.

Some ugly xenophobic traits, however, have also become apparent. The outgoing ruling council decreed that no candidate for prime minister should have either a foreign passport or a foreign spouse, thus forcing a series of prominent returnees either to withdraw their candidacy or to disavow a second nationality. The issuing of visas to foreigners is also fraught, with Islamists in the relevant ministries suspected of being loth to welcome Westerners. Journalists thought to portray the country too candidly have been castigated.

Establishing the rule of law remains the most daunting and urgent task for the incoming government. The Supreme Security Committee, an agency set up under the national transitional council, has acquired too much power, lacks accountability and may have been responsible for the lackadaisical response to the desecration of the Sufi shrines. The Salafist groups, especially in the east, who have been committing crimes such as the murder of Mr Stevens, need suppressing fast. On September 11th the UN’s secretary-general called for fair trials and decent treatment for 7,000 detainees, most of them held by the justice ministry or by local military councils or security committees.

A former Western ambassador who monitors the new Libya airs three possible scenarios: the first, eyeing the rapid recovery of the oil industry and rapid progress towards democracy, he called “nothing succeeds like success”. That, he reckoned, had a 30% chance of realisation. The second was a “downward spiral” into disaster, spurred by factional fighting and government chaos. That, he surmised, had a 20% chance of coming true. Most likely, he reckoned, Libya would “get by”, with dodgy security and messy politics for some time to come. That was the likeliest outcome; on balance, it would count as a success.