Mohammed Merah, French law enforcement officials said, started his career as an Islamic terrorist on March 11 by shooting a French soldier of Muslim origin in the head at close range after telling him, “You kill my brothers, so I am killing you.”

Merah, a 24-year-old French national of Algerian heritage, ended his career — and his life — at 11:30 a.m. Thursday by bursting out of the bathroom where he was hiding and opening fire with a vintage Colt .45 pistol on a squad of highly trained commandos who had pushed into his Toulouse apartment after a 31-hour siege.

The young man fired so many rounds that the semiautomatic pistol sounded like an assault rifle, said Francois Molins, the chief Paris prosecutor heading the investigation into Merah’s actions. The police fired back as Merah fled toward a sliding window opening onto a balcony, Molins said, putting a bullet through his head and sending him plunging lifeless to the ground. Interior Minister Claude Gueant said two of the commandos were lightly wounded.

In the interval between March 11 and Thursday’s violent end, Merah had made France tremble with his cold-blooded killings, riding up on a motor scooter and methodically opening fire on unsuspecting people in the southwestern French cities of Toulouse and Montauban. According to what he told police negotiators, his motive was to avenge the deaths of Palestinian children in Israeli-occuppied territories, France’s military involvement in Afghanistan and a year-old French law banning full-face Muslim veils.

On March 15, Merah shot two more French soldiers, both of them Muslims, in the head and grievously wounded a fourth, a black Frenchman whose family is from the Antilles. According to a self-filmed video viewed by investigators, he shouted “Allahu Akbar,” or “God is great,” as he fired. Four days later, using the same pistol, he shot dead three Jewish schoolchildren and a rabbi in front of the Ozar Hatorah school in Toulouse. Those four victims were dual Israeli-French citizens.

The list of Merah’s victims reads like an advertisement for French multiculturalism, encompassing the estimated 5 million Muslims who live here. But fears arose immediately that the bloody episode could harden resentment of Muslims and other immigrants, already stirred by a bitter presidential campaign ahead of a two-round election set for April 22 and May 6.

In that light, only minutes after police picked up Merah’s slim body, draped in a traditional Arab djellaba covering a bulletproof vest, President Nicolas Sarkozy went on television to draw lessons from the tragic 11-day episode. The first and most important, he said, was that France’s ethnic and religious groups must remain united under the flag.

“Today the French people must overcome their indignation and avoid giving free rein to their anger,” he said.

Mohammed Moussaoui, head of the French Council of the Muslim Faith, and Gilles Bernheim, France’s chief rabbi, issued a statement expressing “relief” that the drama was over and calling on French people to “reflect” on its meaning.

But in an example of what Sarkozy was referring to, Olivier Athouel, whose child attends Ozar Hatorah but was unhurt, told a television interviewer that he was glad the standoff at Merah’s apartment ended in his death. It would have done no good to put him on trial, Athouel said, because he was not even human.

“His life is gone, and so much the better,” he added.

Sarkozy seemed to give some rein to his own anger as he resumed his reelection campaign with a rally Thursday evening in Strasbourg. From now on, he declared, anybody caught consulting jihadist Web sites regularly in France or traveling abroad for jihadist training would face prosecution, as would anybody who preaches violence to Muslims in mosques or prisons.

A major worry for Sarkozy’s campaign is Marine Le Pen, the candidate of the ultra-right National Front. Even as Merah was still at large, she condemned the political establishment — with Sarkozy at the top of the list — for ignoring warnings that the growing number of Muslims and other immigrants among France’s 65 million residents was causing a strain and must be rolled back.

Merah, who was born in a Toulouse suburb, was not an immigrant; he was one of the several million French-born Muslims who sometimes appear to feel out of place in their own country. His acquaintances told reporters he never seemed very interested in religion as he grew up and at one point went in for punk clothes.

Investigators said they were uncertain at what point he homed in on the jihadist message. But they said he traveled to Afghanistan in 2010 and to the Afghan-Pakistani border the following year for what he described to police as military training. Since then, he had been on a watch list maintained by the Interior Ministry, officials said.

A U.S. counterterrorism official who spoke on the condition of anonymity said Thursday that Merah was also on the list of known or suspected terrorists prohibited from flying to the United States and had been since 2010, the Associated Press reported.

The French Defense Ministry said that before his jihad-related travels, Merah had tried once to enlist in the regular French army and once in the Foreign Legion. Both times he was turned down, the ministry said, because of a long record of juvenile offenses such as purse snatching and dealing in stolen goods.

Mathieu Guidere, an Islamic studies professor at the University of Toulouse II, warned in a recent book, “The New Terrorists,” that unfocused youths such as Merah have become a more immediate terrorist threat in recent years than known groups such as al-Qaeda. They can more easily stay under the radar, Guidere argued, absorbing jihadist motivation and techniques on the Internet without heeding a chain of command.

In hours of negotiations during the standoff at his apartment, Merah followed the pattern: He invoked al-Qaeda as his inspiration, police said, but gave no indication he was following anybody’s orders or working as part of a larger group. At the same time, said Molins, the prosecutor, police were seeking clues to how the unemployed Merah could afford his rented car, his two automatic rifles, his several pistols and his trips to Afghanistan.

“We are investigating whether he had any accomplices,” Sarkozy said.