ANKARA, Turkey — Turkey’s highest court on Thursday ruled that the country’s two month-old ban on YouTube violates constitutional rights to freedom of expression, a setback for Prime Minister Recep Tayyip Erdogan who wanted to shut down the video-sharing website.


The Constitutional Court said it would order telecommunications authorities to “ensure that the rights violation is removed,” the state-run Anadolu Agency reported. It was not clear how soon access to YouTube would be restored.


The restrictions on YouTube were imposed in late March after the leak of an audio recording of a government security meeting. In the recording, senior officials appeared to be discussing a possible military intervention in Syria. A lawyer representing YouTube, the Turkish Bar Association and legislators from Turkey’s main opposition party appealed to the high court, seeking to overturn a ban they called unconstitutional.


Turkey also blocked access to Twitter in March – hours after Erdogan threatened to “rip out the roots” of the micro-blogging site. But early last month, the high court also ordered Turkish authorities to end the ban on Twitter.


The moves by Turkish authorities to block the social networks have provoked widespread criticism by Western governments and human rights organizations.


Following the Twitter ruling, Erdogan said his government would comply, even though it did not respect the decision.


Many tech-savvy users, including Erdogan ally President Abdullah Gul, found ways to circumvent the bans both on Twitter and YouTube while they were in place.