IT WAS the sort of attack that the French government has dreaded for several months. Only in December Manuel Valls, the prime minister, declared gravely that France had “never faced a greater terrorist threat”. On January 7th armed gunmen burst into the Paris offices of Charlie Hebdo, a newspaper known for its defiant publication of satirical cartoons, and shot dead ten people. Two police officers were also killed. President François Hollande, who arrived swiftly at the scene, was in no doubt: it was “a terrorist attack” of “extreme barbarity”. It was also the worst act of terrorism to be perpetrated on French soil for over 50 years.

The choice of target was not random. Charlie Hebdo has prided itself over the years for putting free speech above political correctness, mocking politics as well as religion, and Catholicism as well as Islam. In 2006 it reprinted provocative cartoons of the Prophet Muhammad that had provoked consternation and terrorist threats when they were first published by a Danish newspaper, Jyllands-Posten. (The Economist chose not to publish them.) Five years later, Charlie Hebdo published an entire edition that it entitled Charia Hebdo, which it advertised as having been “edited” by the Prophet. During the night just before publication, its Paris offices were firebombed.

Since then, the paper’s offices and some of its cartoonists have been placed under police protection. But this was still not enough to stop two gunmen, armed with semi-automatic weapons, forcing their way in and shooting dead the ten journalists, including Stéphane Charbonnier (known as Charb), its editor and best-known cartoonist. One of the policemen killed was thought to be his bodyguard. Bernard Maris, an economist at the paper, was also killed.

French politicians on the left and the right were quick to condemn the attack. Mr Hollande cleared his diary in order to visit the scene and later held an emergency cabinet meeting on security. Nicolas Sarkozy, the centre-right opposition leader and former president, called the incident an “abject act” and an “attack on our democracy”. French Muslims too expressed outrage over the terrorists. Hassen Chalghoumi, the imam of Drancy and a Muslim moderate, declared that “their barbarism has nothing to do with Islam”.

With the gunmen still on the run, and France’s terror alert raised to its highest level, questions soon turned to why and how this deadly attack had come about. France is no stranger to terrorism, much of it in the post-second world war period linked to the bloody fight for Algerian independence and its aftermath. In 1995 eight people were killed in an attack on the RER suburban underground, and two more died in a similar attack a year later.

The government estimates that as many as 1,000 Frenchmen have either left to fight for Islamic State, already returned, or are on their way back. The January 7th attack appears to have been well planned and executed. “These are guys who have been trained to fight, not to blow themselves up,” says François Heisbourg, of the Foundation for Strategic Research. If they are linked to Islamic State, he suggests, they may be less interested in influencing French policy than in demonstrating their murderous capacity.

In an attempt to curb recruitment by Islamic State, the French government last autumn tightened its anti-terrorism legislation, making it easier to detain suspects at airports and to confiscate their passports. But Mr Valls and Bernard Cazeneuve, the interior minister, have remained keenly aware that a possible attack by home-grown jihadists could take place at any moment. Mr Valls, himself a former interior minister, has repeatedly voiced his worries about imminent terrorism in recent months.

The difficulty for France now will not only be how to deal with the shock, the aftermath and the immediately heightened security worries that will follow from this week’s attack. Home to Europe’s biggest Muslim minority, some 5m-6m strong, the country has been struggling for several years to strike the right balance between its secular traditions and the (peaceful) demands of Muslim French citizens. In several ways, France has unapologetically reaffirmed its secular republican principles, for example, by outlawing the wearing of religious symbols in schools, such as the Muslim headscarf for women.

Yet fears that the country has nonetheless ceded too much ground to Muslims have also helped Marine Le Pen’s populist National Front to flourish. Many opinion polls suggest that she could make it through to the second round of voting in the 2017 presidential election. Indeed, just such a scenario is at the heart of a provocative new novel that was published on the same day as the terrorist attack, by Michel Houellebecq, the enfant terrible of French literature. He imagines a France in 2022 that is run by a Muslim president who has beaten Ms Le Pen in a second-round run-off, and then imposes conservative Islamic principles and education on the country. Critics have denounced the novel as a piece of far-right scare-mongering.

Meanwhile on Wednesday evening, tens of thousands of ordinary French people in towns across the country turned out at vigils in a show of sympathy for Charlie Hebdo. There were similar demonstrations abroad, including in London. But, as terror attacks on other cities besides Paris have shown, it often takes time to recover from these sorts of national tragedies. They may also leave a lasting mark on the country’s political culture in ways that are not always immediately clear at the time.