Egypt's parliament has passed a law that could protect senior military commanders from being prosecuted over the deadly crackdown that followed the overthrow of President Mohammed Morsi.

The current President, Abdul Fattah al-Sisi, will be able to name officers he wants to give lifelong reserve status.

They will gain ministerial privileges and immunity for any crimes committed between July 2013 and June 2014.

More than 1,000 protesters are believed to have been killed during that period.

Between 16,000 and 41,000 other people were reportedly arrested or detained, and hundreds were handed death sentences after mass trials.

Most of them were supporters of Morsi's now-banned Islamist movement, the Muslim Brotherhood, but liberal and secular activists have also been targeted.

The legislation approved by parliament on Monday - known as the "Law Governing the Treatment of Certain Senior Commanders of the Armed Forces" - will allow the president to designate a number of high-ranking officers as lifelong reserves.

The officers will be given the benefits and rights of a sitting government minister, and will enjoy diplomatic immunity when travelling abroad.

They also will be protected from prosecution for any offences committed in the course of duty between 3 July 2013 - the day Mr Sisi led the military's overthrow of Morsi following mass protests against his rule - and 8 June 2014 - when Mr Sisi was sworn in as president for the first time.

That period featured one of the bloodiest episodes in Egypt's modern history.

On 14 August 2013, soldiers and police violently broke up two sit-ins by tens of thousands of Morsi supporters in Rabaa al-Adawiya and Nahda squares in Cairo, killing at least 900 people.

Security forces also reportedly killed 60 protesters gathered outside the Republican Guard headquarters in Cairo on 8 July that year; 95 protesters at the Manassa Memorial on 27 July; and 120 protesters at Ramses Square on 16 August.

An Egyptian government committee looked into the killings and did not recommend charges against any government official or member of the security forces.

But Human Rights Watch said the widespread and systematic nature of those killings suggested that they were part of a policy to use lethal force against largely unarmed protesters.

Amr Magdi, the group's Middle East researcher, said the immunity law approved on Monday showed that "military personnel who know that they have committed crimes that might rise to crimes against humanity are trying to protect themselves from any potential for accountability in the future".

"Although they are extremely powerful now, they know how grave the offences they were involved in are and are aware that time can and will change when finally justice will find its own way," he told the BBC.

HRW also warned on Monday that the Egyptian authorities were increasingly using counterterrorism and state-of-emergency laws and courts to unjustly prosecute journalists, activists, and critics for their peaceful criticism.

Those recently arrested include the well-known blogger and rights defender, Wael Abbas, and Amal Fathy, a political activist and the wife of the head of the Egyptian Commission for Rights and Freedoms, and the comic Shady Abu Zaid.