A leading Iraqi expert on armed groups, who advised governments and appeared frequently in the media, has been shot dead in the capital, Baghdad.

Hisham al-Hashimi was killed near his home in the Ziyouna district on Monday night by two gunmen riding a motorbike.

No group has said it was behind the shooting, but he had reportedly been threatened by the Sunni jihadist group Islamic State and Shia militias.

Prime Minister Mustafa al-Kadhimi blamed groups “outside the law”.

“We vow to his killers that we will pursue them so they are justly punished. We will not allow assassinations to return to Iraq for a single second,” a statement said.

On Tuesday, a top police officer who was in charge of security in the area where Mr Hashimi lived was sacked, the Shafaq news website cited the interior ministry as saying. No reason was given for Brig-Gen Mohammed Qasim’s dismissal.

The US embassy in Baghdad said in a Facebook post that it was “deeply shocked and saddened by the cowardly murder” of Mr Hashimi.

“Our deepest condolences to his family and to the people of Iraq for the tragic loss of this Iraqi national treasure. We call on the Iraqi government to bring those responsible for his murder to swift justice.”

UN special representative Jeanine Hennis-Plasschaert also expressed shock.

“We strongly condemn this despicable act of cowardice,” a statement said.

His body was carried in a small, simple cortege through the streets of Baghdad, but Hisham al-Hashimi was also borne by the wave of grief and shock which swept round the world.

Everyone he had somehow found time for was suddenly connected: young journalists he patiently guided; diplomats needing greater depth of understanding; officials and analysts who had turned to the man now hailed as knowing more than anyone else about everyone with a gun and a grievance imperilling a better future for Iraq.

On social media, even the head of an education charity marvelled how Mr Hashimi had found time for her questions and, of course, lunch, when journalists were queuing for comments.

Iraq’s new Prime Minister, Mustafa al-Kadhimi, another personal friend, vowed to find and punish his killers.

Hundreds of thinkers and doers have been killed with impunity in Iraq. This time the world is watching.

Mr Hashimi’s research focused on Sunni jihadism and he wrote several books on the subject.

When Islamic State (IS) militants seized control of large swathes of Iraq in 2014, he advised the government on how to defeat them and spoke frequently to international news outlets.

Mr Hashimi also commented on the Iran-backed Shia militia groups in Iraq that gained substantial power and influence while helping the government battle IS and have remained unaccountable, despite being incorporated into the security forces.

His work reportedly led to him receiving death threats.

Mr Hashimi’s brother told people at his funeral on Tuesday: “Shortly before the assassination, he told the family about the death threats [IS] had made.”

Acquaintances, meanwhile, told the Washington Post that he had briefly stopped speaking to the media in November after being warned by Kataib Hezbollah, a Iran-backed militia that is suspected of carrying out a series of rocket attacks targeting Iraqi bases hosting US forces and the US embassy in Baghdad.

Iraqi activist Ghaith al-Tamimi also tweeted screenshots of what he said were WhatsApp messages sent about a month ago by Mr Hashimi, in which he wrote that he had been threatened by Kataib Hezbollah and asked for advice.

Mr Tamimi told the US-based outlet Alhurra that he had subsequently advised Mr Hashimi over the phone that he should leave Iraq “by any means”.

However, Mr Hashimi remained in Baghdad and continued his media work.

He recently commented on a raid on a Kataib Hezbollah facility ordered by Prime Minister Kadhimi, who has vowed to crack down on groups operating outside the law.

“Even if this operation does not lead to a legal or judicial result or it ends with a political settlement or a judicial settlement, it still has given the necessary message to the security forces and the judiciary to allow them to overcome the barrier of fear made by these armed groups,” he told the New York Times.