A critic of Turkey's government, arrested in Spain at Turkey's request, has been granted conditional release.
German-Turkish writer Dogan Akhanli has written extensively about human rights in Turkey.
He usually lives in Germany, where his arrest is seen as politically motivated, and Chancellor Angela Merkel has criticised Turkey over the case.
Mr Akhanli is being released on condition that he stays in Madrid, his lawyer said.
"The fight was worth it," Ilias Uyar said in a Facebook post after the hearing. "Dogan Akhanli is free."
Mr Akhanli was detained on Saturday in the city of Granada, where he was reportedly on holiday.
The arrest was carried out on an Interpol "red notice" - a request to arrest a wanted individual for extradition. The request is made by national police forces, and it does not indicate the person is wanted by Interpol itself.
Mrs Merkel, speaking at a televised forum with voters, welcomed Mr Akhanli's release but warned Turkey against misusing Interpol to go after its critics.
"It's not on," she said, adding that other similar cases had forced Germany to "massively change our Turkey policy".
Large numbers of journalists have been jailed in Turkey since a failed coup last year, and news outlets critical of President Recep Tayyip Erdogan have been shut down or taken over.
Tens of thousands of people, including academics and government officials, have also faced arrest.
Mr Akhanli's own website describes him as a former "political prisoner" in Turkey between 1985 and 1987. He fled to Germany in 1991 as a refugee, achieving citizenship in 2001.
He was arrested again in 2010 when he visited Istanbul, accused of a 1989 armed robbery. He was acquitted and released after a number of months - only to have proceedings reinstated at a later date.
German Foreign Minister Sigmar Gabriel has intervened on the writer's behalf, requesting that he not be extradited from Spain.
The incident comes at a difficult time in German-Turkish relations.
In February, German-Turkish journalist Deniz Yucel, who works for Germany's Die Welt newspaper, was detained in Turkey over allegations of producing terrorist propaganda. He remains in police custody.
In March, President Erdogan accused German officials of acting like Nazis after Germany's cancellation of rallies among ethnic Turks ahead of a referendum on greater powers for the Turkish president.
And earlier this week, Mr Erdogan urged Turkish voters in Germany not to vote for the country's main parties.
The two countries are major trade partners and military allies in Nato.