Demirtas, one of two former co-leaders of the leftist pro-Kurdish Peoples' Democratic Party (HDP), was arrested in November 2016 over his alleged links to Kurdish militants.
At the time of his arrest he was a member of parliament.
The court in the French city of Strasbourg said it accepted that Demirtas had been arrested on "reasonable suspicion" of committing a crime, but said the reasons given for keeping him behind bars were not "sufficient" and constituted "an unjustified interference with the free expression of the opinion of the people".
Twin bombs kill 86 at pro-Kurdish rally in Turkish capital
It found that the extension of his detention, particularly during a referendum on expanding President Recep Tayyip Erdogan's powers and later a presidential election, were aimed at "stifling pluralism and limiting freedom of political debate, which was at the very core of the concept of a democratic society".
"The court therefore held, unanimously, that the respondent state was to take all necessary measures to put an end to the applicant’s pre-trial detention," it added.
The ECHR hears cases of alleged violations of the European Convention on Human Rights of which Turkey is a signatory.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ