The European Court of Human Rights (ECHR) has ordered Turkey to release an opposition politician from prison.
Selahattin Demirtas, of the pro-Kurdish Peoples' Democratic Party (HDP), came third in this year's presidential elections, contesting it from jail.
The ECHR said his detention had the "ulterior purpose of stifling pluralism and limiting freedom of political debate".
But Turkey's President Erdogan said the ECHR rulings were not binding.
"We will make a counter-move and finish the job," he told the state-funded Anadolu news agency.
Turkey is part of the Council of Europe, in which member states agree to follow rulings of the ECHR.
Mr Demirtas, who has been detained since November 2016, faces dozens of charges, and prosecutors are seeking up to 142 years in prison if he is found guilty.
His lawyer said he had applied for release following the ECHR ruling.
Who is Selahattin Demirtas?
Mr Demirtas is a former co-chair of the pro-Kurdish Peoples' Democratic Party (HDP).
Ethnic Kurds are the biggest minority in Turkey, making up about 15-20% of the population. But it was not until the 2015 elections that the HDP reached the 10% threshold which that it enter parliament – becoming the first pro-Kurdish party to do so.
The HDP's rise was, in part, at the expense of President Erdogan's ruling AKP, which lost its outright majority in that election.
Mr Demirtas, a 45-year-old human rights lawyer, was widely seen as the charismatic face of the party while it tried to portray itself as a moderate force. It appealed not only to Kurds, but to leftists, environmentalists, and others.
His party also acted as a mediator in ill-fated peace talk between the Turkish government and the Kurdistan Workers' Party (PKK), which is classified as a terrorist group by Turkey and its allies, including Nato.
Mr Demirtas and his fellow HDP party members have long denied any formal connection to the outlawed PKK or other Kurdish armed groups.
He was arrested along with his co-party leader Figen Yuksekdag, after the PKK peace talks had broken down and a fresh wave of attacks began.
What is he accused of?
The initial charges in 2016 related to spreading propaganda for militants fighting against Turkey. Mr Demirtas and his colleagues had failed to co-operate with a counter-terrorism investigation, authorities said.
He was arrested after parliamentary immunity was lifted from selected MPs.
At the time, BBC Turkey correspondent Mark Lowen called it a "major escalation" of the clampdown that began after a failed coup in July 2016.
In early 2017, Mr Demirtas faced new charges including leadership of an armed terrorist organisation, incitement, and the organisation of unlawful demonstrations.
What did the ECHR finding say?
The ECHR said Mr Demirtas had been arrested on reasonable suspicion of committing a crime.
But it found that Turkey had violated the right to be brought promptly before a judge, the limitation on restricting a person's rights, and the right to free elections.
Judges had extended his detention on grounds that were not sufficiently justified, it added.
"His inability to take part in the activities of the National Assembly.... constituted an unjustified interference with the free expression of the opinion of the people and with his right to be elected and to sit in Parliament," it said in a statement.
It also found, "beyond reasonable doubt", that his time in prison "had pursued the predominant ulterior purpose of stifling pluralism and limiting freedom of political debate".
In a unanimous verdict, the court ordered Turkey "to take all necessary measures to put an end to the applicant's pre-trial detention."