Pakistan Prime Minister Imran Khan had hoped a fight over cartoons of the Prophet Mohammed would result in an easy win -- placating the ultra-conservative quarters at home while being hailed as a defender of Islam abroad.

The gamble seems to have backfired spectacularly.

For the past week, riots have again engulfed Pakistan, with police officers killed and taken hostage, and the French embassy taking the "urgent" step of advising its citizens to leave the country.

Khan is now scrambling to keep order, months after launching a war of words with President Emmanuel Macron following the French leader's defence of the magazine Charlie Hebdo's right to republish images of Mohammed -- an act deemed blasphemous by many Muslims.

When Macron openly backed the magazine, Khan took up a crusade -- accusing the French leader of insulting Islam and using an address to the United Nations as an opportunity to lambast the West.

But rather than appease the religious right, Khan's grievance appears only to have encouraged the extremists, with the radical Tehreek-e-Labbaik Pakistan (TLP) -- the Movement at the Service of the Prophet -- calling for the expulsion of the French ambassador.

"I think the prime minister has realised that appeasing the radical forces isn't an easy task because when you try to please them they demand more and more," security analyst Amir Rana told AFP.

"So far he has failed to maintain the balance."

Few issues resonate in Islamic Pakistan quite like blasphemy, where the publication of the cartoons in Europe has long stoked outrage.

"No Pakistani politician or military dictator has or is going to challenge the idea that the honour and the sanctity of Islam and the prophet, and his person in particular, are not important to them," said political analyst Mosharraf Zaidi.

"Any time that the prime minister is representing that view, it's one that has salience in the Pakistani mainstream."

Khan's rhetoric coincided with a wave of Francophobia that prompted a nationwide boycott of French goods, and upstart party TLP sent its supporters into the streets.

The outrage quickly boiled over into violence.

In September, a Pakistani national stabbed two people outside Charlie Hebdo's former office in Paris just days after Khan railed against Islamophobia at the UN general summit.

Pakistan Prime Minister Imran Khan's gamble seems to have backfired spectacularly
Pakistan Prime Minister Imran Khan's gamble seems to have backfired spectacularly AFP / Wakil KOHSAR

The assailant later admitted to being inspired by the likes of Khadim Rizvi, the late leader of the TLP.

The protests in Pakistan reached a violent climax in November when the group laid siege to the capital, Islamabad, sparking days of fighting.

The violence only ended after Khan's government allegedly agreed to a deal with the TLP that would see the French ambassador booted out after receiving parliamentary approval.

But last week, the TLP said the government had reneged on the agreement -- a deal officials have been vague about -- and its new leader Saad Rizvi called for a march on Islamabad, to take place on Tuesday.

When his arrest was met with nationwide rioting, Khan's government retaliated by officially banning the TLP -- effectively labelling them a terrorist outfit.

"No one can be above the law and the constitution," tweeted Khan over the weekend, where he also called for Western nations to outlaw blasphemous speech.

But even then he hedged his bets, suggesting he sympathised with their ideology, if not their methods.

Banning the TLP may have little impact, however, as other religious parties have now thrown their support behind the group.

"The Pakistani state has, over decades, actively fostered the ideology that led to the TLP and that leads many in the population to sympathise with the TLP," said Madiha Afzal, a Brookings Institution fellow.

"Khan attempted to try to thread this needle in his tweets about the group... but it is a tough line to walk: not disavowing the group's ideology and demands while taking action."

Khan appears to have few easy options -- crack down even harder on a group claiming to defend Islam and risk sparking a wider confrontation in the deeply religious country.

Or, the government can accede to some of the TLP's demands and embolden religious fanatics to continue using violence in the future as a potent bargaining chip.

"There is no doubt there is a bind," said Zaidi.

"Pakistan has to certainly manage its relationship not just with France and other nations and the rest of the world but it must also be seen to be responsive to the sentiments of Pakistani Muslims."