Kenya’s high court has suspended some anti-terrorism measures signed into law two weeks ago by President Uhuru Kenyatta, in a partial victory for opposition groups who had argued they threatened basic liberties and free speech.

High court judge George Odunga suspended eight clauses, including a cap on refugees, and asked the chief justice – the head of the judiciary – to set up a constitutional court to scrutinise the new law.

The ruling is a setback for Kenyatta, who has faced mounting pressure to boost security since Somali al-Shabaab rebels killed 67 people in a Nairobi shopping mall in September 2013. After further attacks in 2014, he replaced the interior minister and police chief last month.

There was no immediate comment from the government.

Odunga left intact some of the most controversial amendments, including a fourfold increase to 360 days in the length of time suspects can be held without charge, and penalties for media that print material “likely to cause fear or alarm”.

The clauses he suspended included a limit of 150,000 on the number of refugees allowed in Kenya at any one time.

“The government is obliged to take all lawful measures to nip acts of terrorism in the bud, and such measures ought to be supported by Kenyans of all walks of life,” Odunga said in his ruling. “Such moves, however, must pass constitutional and legal muster.”

Kenyatta said when he signed the law on 19 December that it did not go against the bill of rights or any provision of the constitution.

Yash Ghai, a Kenyan constitutional law expert who has been critical of the measures, said Odunga’s ruling paved the way for legal arguments on all of the new security measures.

“The parties didn’t really have time to argue about specific provisions but that will now come,” he said. “I have no doubt that this act is deeply flawed.”

Odunga also criticised the manner in which the law was passed. A brawl broke out in parliament during the debate, when opposition legislators threw books at the Speaker, shouted, chanted and sprinkled water over his deputy.

Kenyan MPs scuffle in parliament over anti-terror bill Guardian

Opposition politicians who had filed the legal challenge, led by former prime minister Raila Odinga, greeted the ruling with jubilation. They punched the air, chanting: “A people united shall never be defeated.”