A gunman suspected of killing seven people, including three Jewish children, in the name of al Qaeda was arrested after a 12-hour police siege in the city of Toulouse, French television channels reported on Wednesday.
In an unfolding drama that riveted France and the world, about 300 police, some in body armour, had cordoned off a four-storey building in a suburb of Toulouse where the 24-year-old Muslim shooter, identified as Mohamed Merah, had been holed up.
President Nicolas Sarkozy was expected to speak to the nation shortly.
Interior Minister Claude Gueant said the gunman was a French citizen of Algerian origin who had been to Pakistan and Afghanistan and had told police negotiators he had carried out his attacks to avenge the deaths of Palestinian children and because of the French army's involvement in Afghanistan.
Authorities in Afghanistan confirmed that Merah had been arrested for bomb making in the lawless southern province of Kandahar in 2007 but escaped months later in a massive Taliban prison break.
Police removed other residents from the building and began evacuating other nearby homes. A police source had said earlier that authorities would not allow the siege to drag on indefinitely.
Sarkozy, running for re-election in five weeks time, said earlier that France should not give way to discrimination or vengeance after the shootings of a rabbi and the three children, and three soldiers of North African origin.
His warning came after far-right leader Marine Le Pen, a rival presidential candidate, said France should wage war on Islamic fundamentalism.
Terrorism will not manage to break our nation's feeling of community, Sarkozy said after meeting Jewish and Muslim community leaders in the Elysee palace in Paris. We must stand together. We must not cede to discrimination or vengeance.
Interior Minister Gueant said Merah, who had been under surveillance since the attack on the first soldiers last week, wanted revenge for Palestinian children and he also wanted to attack the French army because of its foreign intervention.
He told journalists Merah was a member of an ideological Islamic group in France but this organisation was not involved in plotting any violence.
He said Merah had thrown a Colt 45 pistol of the kind used in all the shootings out of a window of the block of flats in exchange for a mobile phone, but was still armed.
Police sources said they had conducted a controlled explosion of the suspect's car at around 9:00 a.m. after discovering it was loaded with weapons.
Merah's girlfriend and brother, also known to authorities as a radical Islamist, have also been arrested, officials said.
Gueant said Merah had contacted the first soldier he attacked under the pretext of wanting to buy his motorcycle.
Investigators identified the IP address he used - that of his mother - because he was already under surveillance for radical Islamist beliefs.
We knew, and that is why he was under surveillance, that he had travelled to Afghanistan and Pakistan, the minister said.
The telephone of the man and his family was tapped from Monday and with the help of other information the police decided to raid his house. Merah has a criminal record in France, Gueant said, but nothing indicating such an attack was possible.
A police source told Reuters that investigators had also received a tipoff from a scooter repair shop in Toulouse where the gunman asked to change the colour of the Yamaha scooter used to flee the shootings and to remove a GPS tracker device.
A group of young men from Merah's neighbourhood described him as a polite man of slight build who liked football and motorbikes and did not seem particularly religious.
He isn't the big bearded guy that you can imagine, you know the cliche, said Kamal, who declined to give his family name. When you know a person well you just can't believe they could have done something like this.
Sarkozy had been informed of the standoff early in the morning, officials said. The president's handling of the crisis could be a decisive factor in determining how the French people vote in the two-round presidential elections in April and May.
The Jewish victims from the Ozar Hatorah school were buried in Jerusalem on Wednesday. Parliament speaker Reuben Rivlin said in his eulogy at the hill-top cemetery that the attack was inspired by wild animals with hatred in their hearts.
Authorities said on Tuesday that the gunman had apparently filmed his rampage through the school. He wounded Rabbi Jonathan Sandler as he entered the building, then shot an 8-year-old girl in the head, before returning to kill Sandler and his two children, who had rushed to his side, at point blank range.
Immigrants and Islam have been major themes of the campaign after Sarkozy tried to win over the voters of Le Pen, who accused the government on Wednesday of underestimating the threat from fundamentalism.
We must now wage this war against these fundamentalist political and religious groups that are killing our children, that are killing our Christian children, our Christian young men, young Muslim men and Jewish children, she told the i-Tele news channel, questioning the decision to deploy in Afghanistan.
But leaders of the Jewish and Muslim communities said the gunman was a lone extremist.
France's military presence in Afghanistan has divided the two main candidates in the election. Socialist frontrunner Francois Hollande has said he will pull them out by the end of this year while Sarkozy aims for the end of 2013.
Jean Marc, a 56-year-old restaurant owner in the city who declined to give his last name, said he believed the crisis would benefit the far right or Sarkozy in the election.
The Socialists don't talk about this stuff and it shows they don't know what they are doing, he said. They (the police) need to get this guy.
(Additional reporting by Brian Love, Daniel Flynn and Geert de Clercq in Paris; Writing by Daniel Flynn; Editing by Giles Elgood)