Kenya’s High Court has suspended some sections of the controversial new security law, which was enacted two weeks ago amid fierce opposition.
The court blocked eight clauses until a legal challenge mounted by the opposition and rights groups is heard.
MPs had exchanged blows while debating the law, which the opposition said would turn Kenya into a “police state”.
The government says the measures are necessary following a wave of attacks by Somalia-based Islamist militants.
Some 500,000 Somali refugees live in Kenya and the government suspects some of them have links to al-Shabab militants.
High Court Judge George Odunga said that freedoms and inalienable rights could not be limited under the pretext of fighting terrorism, AP news agency reports.
Opposition leader Raila Odinga and his supporters cheered in court as the judge handed down his ruling.
The court suspended measures which could jail journalists who “undermine investigations or security operations relating to terrorism”, and limit the number of refugees in the country.
The security law prescribes long jail terms for anyone convicted of terror-related offences, in particular anyone found with weapons inside a place of worship.
Owners of buildings or institutions, or persons in charge of public places who fail to prevent entry of weapons into such areas can also be liable to 30 years in jail.
Terror suspects can be detained for 24 hours before being presented to court. They can then be held for up to 30 days. Earlier reports had suggested suspects could be held up for up to a year.