Former Malaysian prime minister Mahathir Mohamad tweeted Thursday that Muslims had a right "to kill millions of French people" after a deadly attack in Nice, sparking widespread anger and prompting Twitter to delete his post.

Three people were killed at a church in the southern French city, with the attacker slitting the throat of at least one, in what authorities were treating as the latest jihadist assault to rock the country.

Shortly afterwards, Mahathir -- the prime minister of Muslim-majority Malaysia until his government collapsed in February -- launched an extraordinary outburst in a series of tweets.

Twitter initially declined to remove the comments, but finally did so following a furious reaction from the French government.

Cedric O, the French junior minister for digital affairs, said in a tweet in French and English: "I just spoke with the MD (managing director) of @TwitterFrance.

"The account of @chedetofficial must be immediately suspended. If not, @twitter would be an accomplice to a formal call for murder."

Twitter initially flagged Mahathir's tweet about killing "millions of French people" as "glorifying violence" but did not remove it.

However, shortly afterwards, the tweet was deleted entirely, and Twitter told AFP it was because the comments "violated policy regarding glorification of violence."

Mahathir never made a direct reference to the attack in Nice however.

Referring to the beheading of a French teacher who had shown pupils cartoons of the Prophet Mohammed, Mahathir said he did not approve of his murder but that freedom of expression does not include "insulting other people".

"Irrespective of the religion professed, angry people kill," said the outspoken 95-year-old, who has in the past drawn controversy for remarks attacking Jews and the LGBT community.

"The French in the course of their history has killed millions of people. Many were Muslims. Muslims have a right to be angry and to kill millions of French people for the massacres of the past."

But he added that "by and large the Muslims have not applied the 'eye for an eye' law. Muslims don't. The French shouldn't."

Mahathir, who served as Malaysian prime minister twice for a total of 24 years, also said French President Emmanuel Macron was "not showing that he is civilised", and added that he was "very primitive."

"The French should teach their people to respect other people's feelings. Since you have blamed all Muslims and the Muslims' religion for what was done by one angry person, the Muslims have a right to punish the French.

His comments sparked widespread condemnation, with some social media users labelling them "outrageous" and "disgraceful".

The beheading of French teacher Samuel Paty reinforced Macron's intention to take on Islamic extremism.

But comments by the French president since then, in particular a vow to protect freedom of speech including cartoons deemed insulting by Muslims, have inflamed tensions.

Protests and calls for boycotts against France have erupted in several Muslim countries.