It is hard to describe exactly what happens when a whole country goes into shock, but this is what seemed to happen in France on Monday 19 March. The most visible signs in Paris were armed soldiers in shopping malls and train stations, bomb alerts on the Métro and, despite the sunny weather, far fewer customers than usual at the café terrasses. More telling still was the subdued atmosphere everywhere in the city. Certainly by the time of the evening rush hour there was a distinct sense that all everybody wanted to do was to get home to safety and the evening news on television.

The reason for all of this was the news from Toulouse of the murder of a 30-year-old man and three small children at a Jewish school just outside the city. That morning, as Rabbi Jonathan Sandler was dropping off his two boys, aged five and three, at the Ozar HaTorah school at about 8am, all three were shot dead by an armed man on a Yamaha TMax scooter. Other teachers and pupils thought at first that the noise of the shots was fireworks. But as they approached they saw the terrible scene of another pupil, Miriam Monsonego, the eight-year-old daughter of the school's director, being pulled back by her hair. The gunman then blasted a bullet through her temple. This scene was captured by security cameras at the school. Understandably, very few people have seen this footage. For most of France, imagining the image - even just knowing that it existed - was more than enough.

At first there were theories about a rogue soldier or a neo-Nazi psychopath on the loose. These theories were given credence by the fact that the previous week two French soldiers of North African origin had been killed in the same region by someone using the same weapon and techniques. But then, if such a thing was possible, events took another turn for the worse. At 1am on Wednesday 21 March, an editor at the French news channel France 24, Ebba Kalondo, was just about to pack up for the night when she received a call from a phone box in Toulouse from somebody who claimed responsibility for the murders. She heard a young man, "apparently in his twenties, very calm, who spoke impeccable French, placing a great weight on his words".

He went on to give details of all the murders which only the killer could have known. He said that he was linked to al-Qaeda, and that his aim was to protest against the French law banning the veil and to take revenge on the French army for its action in Afghanistan and the Israelis for the killing of Palestinian children. He said he was proud of his actions; that he had bought his weapons in France and that he would "go to prison with his head held high, or die with a smile on his face". He declared that he "wanted to bring France to its knees".

Within two hours, the French police had traced the caller - Mohamed Merah - to a flat in a building at 17 rue du Sergent-Vigné in Côte Pavée, a suburb 20 minutes from the centre of Toulouse. It turned out that Merah was not only the owner of the Yamaha scooter but also heavily armed. After an initial attempt to break into the apartment building, special police units settled down into a siege. In the next few hours Merah claimed to have filmed the killings at the Jewish school and given the tapes to his "brothers" to distribute on the internet. He said he would trigger assaults in Lyons, Marseilles and Paris.

On Thursday morning, Merah again confronted the police as they made another assault on the building. He was wearing a bulletproof vest and carrying a Colt 45 when he was shot dead with a bullet to the brain by a sniper.

It was only then that the full complexity of the story began to take shape. As Le Monde described it, from this point on, the murders were no longer "un fait divers" (a mere news story) but "un fait politique" (a political fact). This much had already been anticipated by President Nicolas Sarkozy who had gone straight to Toulouse on Tuesday afternoon in his traditional role of "protector" of the French nation. Other politicians (with the notable exception of Marine Le Pen, on the far right) publicly undertook not to make political capital out of the killings. But once Merah's identity was made known, neutrality became impossible.

Mohamed Merah was not simply an Islamist killer. He was also a French national with an Algerian background, a toxic truth that sent a second shock wave through French society after the killings because this particular dual identity cuts deep into French cultural and political history. On the one hand, that is to do with repressed memories of the Algerian war of independence, fought by Algerians against their French colonial masters and which ended in 1962. But it is also because to be French and Algerian in 2012 is not only to have a ferociously contested identity, but to have an identity that is denied or hated by one side or the other.

The young Algerians of France have been targeted in recent times by Ayman al-Zawahiri, now leader of al-Qaeda. He has declared that France is ready for radicalisation, or, as he puts it, "awakening". Indeed, Zawahiri (who speaks French) reserves a special hatred for France, which he blames for a series of criminal acts in the Middle East, from Napoleon's invasion of Egypt in 1798 to providing Israel with a nuclear reactor. Most important of all, in the French context, Zawahiri has identified North Africa, and Algeria in particular, as ready for "liberation" in the long war against France.

In France, this threat has a special resonance. However much the French media or French intellectuals try to reduce the problem to familiar, domestic issues, the fact remains that France itself is under attack from the angry and dispossessed heirs to the French colonial project. To conflicted young men such as Mohamed Merah, the Algerian war with France remains unfinished business.

The day after the death of Mohamed Merah I made my way to the Barbès district of Paris. This is a tiny, overcrowded space which, largely Muslim and Algerian, provides a neat lesson in French colonial history. I wanted to speak to people here and see for myself the emotional response to the events of a terrible week. As I stepped down off the iron staircase of the Métro during Friday prayers, the area was its usual chaotic self. This part of Paris may have the highest concen­tration of Muslims in the city but it is hardly noted for its piety. Instead, as you walk away from the station, you plunge into packs of Arab lads flogging trabendo - Algerian slang for contraband goods, mainly cigarettes but also wristwatches, dope and cheap alcohol. A floating population of young Arabs and Africans is slouching on benches, smoking weed, gossiping, leering at girls.

In a bar at the far end of the rue des Poissonniers, I ordered a drink and asked the barman what people round here thought of the events in Toulouse on Thursday. "Parle pas français," he said. But then a large black guy, a Muslim from Senegal, said to me: "He can speak French, he just doesn't want to." He then went on - his name was Malik - to say that people here were as shocked as anyone in France.

Further down the road, outside the mosque in the rue Myrha, I chatted to a few lads in hip-hop gear, slightly younger than Merah. They identified themselves as Algerians and Muslims and seemed ready to talk. So, what did they think of the killings in Toulouse? They laughed, partly embarrassed and partly out of bravado. Then one of them began to speak. "That guy was bad," he told me. "He didn't give a fuck. But so what?"

Did that justify what happened? “Who knows?" he said. "Who knows anything? Maybe everything was a set-up to provoke the Muslims . . . We're Muslims. We hear stuff. France is our enemy."

So why live here? "France is easy. No one is hungry. In Algeria you could starve to death. And that's because of the French."

Did they admire Merah?“Fuck knows. He was just a guy who wanted to fight the enemy. He wanted to be a soldier."

A group of older guys now started circling around us, giving me a hard stare. It was time to move on.

Later, I spoke to an elderly Jewish businessman in the next street. He would not give me his name but told me that he had been in Barbès over 30 years, one of the few surviving Jewish businesses in the area. His family was from Fez in Morocco and he spoke fluent Arabic. "Most of my customers are Muslims and we have a good relationship," he said, "and some people have told me that they thought it was bad what happened in Toulouse. But I know it is a façade - that as a collective they feel differently about Jews and Palestine. The worst time I have known is during the last intifada [starting in 2000] when they boycotted all Jews in Paris. But now I think this is worse. On the surface, everything is the same today. But I cannot forget the image of a bullet in the brain of a child. That guy, that Muslim, he was just like a Nazi. He was a Nazi."

The day before the killings of the children in Toulouse was the 50th anniversary of the end of the Algerian war, perhaps the most important moment in the postwar history of France. In truth, 50 years on, there is little to celebrate on both sides. Torture, mass killings and ethnic cleansing were all deployed by the French in North Africa as weapons of war. On the Muslim side, insurgency, terrorism and assassination became legitimate tools to use against the European oppressor. In the aftermath of the war, nationalist forces massacred tens of thousands of harkis, Algerians who had fought for the French.

The blackest part of the story, however, is the Algerian civil war of the 1990s. In 1992 a general election for a new government was abandoned when it seemed likely that the Islamist Front Islamique du Salut (or FIS, the Islamic Salvation Front) would sweep to an overwhelming victory. As the military cracked down on the Islamists, they went underground and started a bloody campaign against the state which lasted until 2002, when a ceasefire and amnesty were declared.

No one will ever know just what happened during that period of war, but what is certain is that hundreds of thousands of people died. Algeria became a slaughterhouse once again. Hundreds of thousands were killed in the dirty war between the government (allegedly aided by French special forces) and Islamist insurgents.

And Paris was once again the target of Algerian extremists. In July 1995, Sheikh Abdelbaki Sahraoui, a moderate imam and founder of the FIS, was gunned down by the terrorist Groupe Islamique Armé (GIA) at the mosque in the rue Myrha. Sahraoui had opposed exporting the war to France, but now his death was followed by a swift succession of bombings of civilian targets in Paris, leaving ten dead and scores wounded. The leader of the Paris cell, Khaled Kelkal, was eventually shot dead by police near Lyons. In a precursor of the 11 September 2001 attacks, the terrorists made plans to crash a plane into the Eiffel Tower.

By chance, Kelkal had given an interview in 1992 to a German sociologist, Dietmar Loch, who was writing his doctoral thesis on the youth of the French banlieue. These are the wretched suburbs, the neighbourhoods outside major towns and cities where most of the immigrant Muslim population is forced to live, practically excluded from the mainstream of French society.

In the interview, Kelkal revealed himself not as a terrorist monster but as an intelligent, sensitive, articulate and reflective young man. He was anguished about his position in French society. "There's no place for me here," he said to Loch. "In the banlieue we are separated from France by a wall, an enormous wall. That's why I wanted to blow it up."

In 2012, in Barbès and across France, there are many young Muslims who feel like this, who despise this country in which they feel trapped. They are not looking for reform or revolution. They are looking for revenge. And this can take strange forms.

For instance, more than one observer has noted how Merah's murderous actions all seem to have been determined by an internal logic related to collective memories of the Algerian war - constructed almost like a bizarre memorial, or anti-memorial. Merah's murder of North African soldiers in the French army has an echo to the slaughter of the harkis 50 years ago. Harki is also a contemporary word and very much alive in the banlieue these days - there is no greater insult. This came to the attention of the wider public when, in 2001, Zinédine Zidane was booed off during a friendly football match between France and Algeria to chants of "Zidane-harki!". The match in Paris was abandoned after a pitch invasion by Algerian supporters, most of them French nationals.

The killing of Jews in France has deep historical resonances. To be French and to be a Jew is a double crime, in the mind of an Islamist such as Merah. More to the point, in colonial Algeria, Jews enjoyed special favoured status under the same French law that excluded Muslims from citizenship. For this reason, Algerian Muslims saw them as traitors who had taken the country by stealth.

Even Merah's method of execution - tearing around a city on a scooter with a gun - seems to pay homage to the tactics of the Algerian nationalist death squads at the height of the so-called Battle of Algiers in the 1950s. But beyond the symbolism, there is a wider strategic meaning to Merah's actions. It does not matter very much whether he was or was not an al-Qaeda operative or, as has been alleged, close to the radical Salafist Forsane Alizza (Knights of Pride), a Toulouse-based group that was banned by the hardline minister of the interior, Claude Guéant, in January. With his actions, Merah has already taken to the next level the al-Qaeda strategy of moving operations away from Pakistan and on to a new front, deeper into North Africa and France.

This shift in al-Qaeda thinking has been developed partly to take advantage of the anticipated political chaos in the wake of the Arab spring, and partly because - as Zawahiri has argued - the moment is right for revenge on France. It is no accident that Zawahiri's threats against France have been followed by a resurgence in activities of al-Qaeda au Maghreb Islamique (Aqmi, al-Qaeda in the Islamic Magh­reb), the North African wing of the movement which has its base in Algeria. It is the fear of French security forces that Aqmi will soon begin to operate on French soil.

The Algerian government is adamant, however, that the Arab spring will not arrive in Algeria. Yet, on recent visits to Algiers, I have found the atmosphere to be crackling with violence. Police in paramilitary gear regularly line up outside the mosques after prayers, threatening and driving worshippers down back into the city and away from a stand-off. Some of the protesters on the streets are retired "terrorists" from the 1990s who took advantage of the amnesty in 2002. Now, they are being replaced by a younger generation who do not wear beards or robes, but dress instead in hoodies, scarves and replica football shirts (Liverpool FC and Olympique de Marseille were the most popular ones). They look like their brothers and cousins in the banlieue of Lyons, Marseilles and Paris. They jeer at the police but just about shy away from physical contact. Their anger is palpable. This conflict has its mirror image back in France.

In recent days, Mohamed Merah has been described in the French press and by politicians as a "un loser", a narcissist, a lone wolf, a one-off. Everybody knows that this is not true. Indeed, what no one wants to say out loud, politicians or media, is that although he may have been a loser, he is far from being alone. For many young Algerians in the banlieue, Islamist activity is more than a religion; it has become a badge of cultural revolt, a weapon of war against a world that they feel hates them and that they hate in return. This is why they describe their conflict as "the French intifada". It is hardly surprising that these young people use the language of the Israel-Palestine conflict to identify themselves with the dispossessed Palestinians, the very wretched of the earth. The worst parts of the banlieue do indeed feel like occupied territory.

More than a week on from the horror of Toulouse, the sense of shock in France is slowly starting to fade. But it is being replaced with an all-too-familiar nightmare - the spectre of Algeria. French politics has almost returned to normal in recent days, but there is also an understanding that many of the critical issues on all sides have been derailed: Sarkozy is forced to debate security with the Front National leader, Marine Le Pen, when really he wants to talk about the economy; the leader of the Parti Socialiste, François Hollande, and others on the left are barricaded into an uncomfortable silence, unwilling to speak on behalf of the banlieue and unable to blame the government for this latest act of terror. In the meantime, Merah's brother has been taken into custody in Fresnes Prison, just south of Paris. I have recently been conducting research in this prison, a relic of the 19th century. It has variously housed members of the French Resistance, collaborators and agents of the Gestapo. In the 1950s and 1960s, scores of Algerian nationalists were guillotined here or shot by firing squad. Now it is home to a huge Islamist presence. Merah's brother will be received there as a hero.

In Algeria, the father of Mohamed Merah has called for his son to be buried in Algeria, where no doubt some will revere him as a martyr. Merah's father has also publicly declared that "France killed" his son, that his death "must be avenged" and that "France will pay".

And so the long war goes on.

Andrew Hussey is the author of "Paris: the Secret History" (Penguin, £10.99)