PARIS — The French Foreign Ministry said Sunday that it was recalling its ambassador to Turkey, a day after Turkish President Recep Tayyip Erdogan sharply criticized French President Emmanuel Macron's response to the beheading of a teacher who had shown students pictures of the prophet Muhammad, strictly prohibited by the Muslim faith.

French Foreign Minister Jean-Yves Le Drian said the country was withdrawing Ambassador Herve Magro from its NATO ally because of a “hateful and slanderous propaganda against France, testifying to a desire to stir up hatred against us and our heart,” as well as “direct insults against the President of the Republic, expressed at the highest level of the Turkish state.”

In the week since the attack in the Paris suburb of Conflans-Sainte-Honorine, Macron’s government has ordered a crackdown on Muslim organizations it accuses of fomenting terrorist violence, and defended the caricatures of Muhammad as emblematic of the French values of secularism and free expression, even if they are deeply offensive to many of France’s Muslim citizens, among its largest minority populations.

History teacher Samuel Paty, 47, was teaching a lesson on free speech when he shared the images with his class. As France mourned his death, it projected the caricatures onto government buildings in cities including Toulouse and Montpellier.

The government’s response has emerged as a flash point in France’s increasingly troubled strategic relationship with Turkey, which offered no public solidarity with France in the aftermath of the killing. Over the past year, the two governments have sparred over the civil war in Libya and Turkish claims to energy deposits in the eastern Mediterranean.

“What is the problem of this person called Macron with Muslims and Islam?” Erdogan said during a speech to members of his political party on Saturday. “Macron needs treatment on a mental level.”

“What else can be said to a head of state who does not understand freedom of belief and who behaves in this way to millions of people living in his country who are members of a different faith?”

The spat has been accompanied by calls online and from some Muslim countries to boycott French products.

It’s the first time France’s government has withdrawn its envoy from Turkey, Macron’s office said. National security analysts viewed the decision as a significant escalation but also as inevitable, given Erdogan’s rising hostility to France in recent months over Libya and the eastern Mediterranean.

“At some stage, if you don’t react, you lose credibility, and I think we had pretty much reached that stage,” said former presidential adviser François Heisbourg, a senior adviser at the International Institute for Strategic Studies.

“On the state-to-state level, it has given a new edge to the rhetorical aspects of the relationship between Turkey and France. But what has changed is that the French, who until now took Turkish insults in stride, clearly have decided that the insults themselves would carry a penalty,” he said.

Others saw two combative and strong-willed leaders who both stood to gain from a showdown in the headlines.

“This is the dream fight for both of them,” said Asli Aydintasbas, a fellow at the European Council on Foreign Relations. “In each other, Macron and Erdogan have found the ideal enemy. This spat works for both leaders in some strange fashion, both domestically and in terms of the influence they are trying to project abroad.”

Erdogan’s jabs at Macron help rally members of his political base who are sympathetic to religious and nationalist appeals focused on foreign threats, she said. They can also bolster his credentials as a leader to the wider Sunni Muslim world. And they reflect his perception of a wider threat from what “he sees as an anti-Turkey axis in the Arab world,” with French allies such as Saudi Arabia and the United Arab Emirates forming the core of that axis.

For Macron, calling out Erdogan was “low-hanging fruit,” given the geopolitical competition between the two governments and the French leader’s desire to fend off right-wing, anti-Islamist challengers at home.

“France is clearly worried about Turkey’s influence over Muslim communities in Europe and Erdogan’s particular brand of Islam,” Aydintasbas said. “When you hear French officials, they equate Turkey with Islamism.”

Paty was killed by an 18-year-old Russian-born Chechen who had been in contact with a Muslim parent offended by Paty’s lesson. Assailant Abdoulakh Anzorov was shot to death by police a short time later.

The attack has triggered a national moment of reckoning in France, traumatized by a string of Islamist terrorist attacks in recent years.

In September, France began the long-awaited trial of 14 alleged accomplices in the deadly 2015 attack on the satirical newspaper Charlie Hebdo. Two brothers affiliated with al-Qaeda killed 12 journalists after the newspaper had published caricatures of Muhammad.

A pillar of French identity is its state secularism, or laïcité, which enforces the strict neutrality of the state and guarantees the liberty of conscience among citizens — the freedom to believe or not to believe. But on a cultural level, beyond the parameters of the law, French politicians have in recent years begun to interpret state secularism as a means of cracking down on public indications of Islam in society, frequently the Muslim headscarf.

The raw emotions over Islam in France have surfaced again in the government’s response to the beheading.

In a television interview last week, Interior Minister Gerald Darmanin attacked the existence of ethnic food aisles in supermarkets, and Education Minister Jean-Michel Blanquer has criticized what he called “Islamo-leftism” in French universities.

In an interview published Saturday with France’s Journal du Dimanche, Blanquer called for France to fight against an “intellectual framework from American universities” that “essentializes communities and identities” and threatens to undermine “our republican model.”