Kenya’s High Court has thrown out key aspects of a tough new anti-terrorism law after a legal challenge by the opposition.
Eight clauses were annulled, including those which curbed media freedom and capped the number of refugees and asylum-seekers to 150,000.
The government said the law was needed to counter the growing threat posed by militant Islamists.
The opposition warned that it violated civil liberties.
Covert operations
The BBC’s Maryam Abdalla in the capital, Nairobi, says that the opposition Coalition for Reform and Democracy (Cord) party applauded the ruling, saying it had saved Kenya from becoming a police state.
The government said it would consider lodging an appeal.
Our reporter says the court had ruled in the government’s favour on some controversial clauses.
These included giving Kenya’s intelligence agencies the power to carry out covert operations to prevent attacks and allowing police to detain terror suspects beyond 24 hours, provided they were first brought to court.
The law was passed during a chaotic parliamentary session in December, following the killing of 64 people in two attacks in north-western Kenya by the al-Qaeda-linked al-Shabab group.
In September 2013, 67 people were killed when al-Shabab militants laid siege to the upmarket Westgate shopping centre in the capital, Nairobi.
On Saturday, al-Shabab posted a documentary-style account of the siege online.
A masked fighter suggested that similar attacks could be carried out on shopping centres in Canada, France, the US and UK.
Al-Shabab is fighting to create an Islamic state in Somalia, but it has been increasingly targeting neighbouring Kenya.
The government alleges that it is recruiting Somalis living in Kenya, and therefore wants to restrict entry to refugees and asylum-seekers.
Kenya has nearly 500,000 refugees, many of whom fled conflict in Somalia.
Kenya sent soldiers into Somalia in 2011 to attack the militants, accusing them of being behind the kidnapping of foreigners on Kenyan soil.
The militants are demanding the withdrawal of Kenyan troops in Somalia.