Image copyright Getty Images Image caption Those in favour of military courts argue that they are important because the government cannot provide adequate security for judges in terror trials

Pakistan's lower house has passed legislation to reinstate secret military courts, despite criticism from human rights activists.

Military courts were first set up as a response to the 2015 attack on a military-run school by the Pakistani Taliban that killed 134 children.

The courts, which try civilians charged with terrorism offences, had a two-year mandate that expired on 7 January.

The legislation still needs Senate approval before it can become law.

Viewpoint: How Peshawar military school massacre changed Pakistan

The government of Prime Minister Nawaz Sharif said in January it wanted to reinstate the military courts, but lacked the two-thirds majority in parliament. After months of discussions between parties, the bill was passed late on Tuesday.

Under the original secret military court system:

Defendants were not allowed to hire their own lawyers - they were assigned one by the military

No media were allowed to observe proceedings

The timing of the trial was not made public until the military announced a verdict

There was no right to appeal

Judges were not required to have law degrees or provide reasons for their verdict

The new bill, however, has some amendments, including allowing suspects to choose their own lawyer.

Under the new law, a suspect must also read the charges at the time of arrest and be produced in a military court within 24 hours, the BBC's M Ilyas Khan in Islamabad reports.

In their first two years, the military courts awarded death sentences to more than 160 people, of whom 20 have been executed, our correspondent says.

After the school massacre, Pakistan lifted a moratorium on capital punishment as part of measures it said were aimed at checking the spread of militancy and extremism. Since then more than 400 prisoners on death row have been hanged.

One of the main arguments made in favour of military courts is that the government cannot provide adequate security to judges who preside over terrorism related cases.

But critics say the courts lack transparency and due process.