Turkey's top court on Thursday overturned parts of a law that granted the country's telecoms authority more powers to monitor online users and block websites.
The law, approved by Turkish President Recep Tayyip Erdogan in September, had allowed telecoms authority TIB to block websites "in order to protect national security, public order and to prevent crime" without a court order.
The new powers, which also allowed the TIB to store online communications and traffic data for up to two years, violated individual rights and freedoms, the constitutional court ruled, clearing the way for it to overturn the law.
Under the ruling, service providers will no longer have to block a website or remove the content within four hours of a ruling by TIB.
The websites can only be blocked upon a court order, the court ruled.
The TIB will not be able to monitor which users visited which websites.
The ruling came after the main opposition Republican People's Party (CHP) submitted a petition to the constitutional court to have the law annulled.
"Ruling by Turkey's constitutional court throws out bad law giving telecom body power to close down internet sites and amass internet user data," Emma Sinclair-Webb, Turkey researcher at Human Rights Watch, wrote on Twitter.
The changes had come on top of a controversial law in February that tightened state control over the Internet, sparking outrage both at home and abroad.
Activists say tens of thousands of websites have been blocked in recent years. This year Turkey topped Google's content removal request list.
Just ahead of the ruling, the TIB on Wednesday temporarily blocked access to an article by Ezgi Basaran, a female columnist for the anti-government Radikal newspaper.
Turkey's Islamic-rooted government blocked Twitter and YouTube in March after they were used to spread audio recordings implicating Erdogan, then prime minister, and his inner circle in a damaging corruption scandal.
The move triggered concerns that Erdogan, who was elected president in August after ruling Turkey as premier for over a decade, was seeking to increase his powers to silence critics and accelerate a slide towards authoritarianism.
YouTube and Twitter were eventually unblocked, after constitutional court rulings that the bans were unlawful.
But Erdogan has made no secret of his disdain for social networks, comparing them to a "murderer's knife" and once famously vowing to "eradicate" Twitter.
The constitutional court, seen as the last bastion of checks and balances in Turkey, has overturned or challenged several government-led laws in recent years.