Berlin – which sees Turkey's bid to have the writer extradited as a politically-motivated move by President Recep Tayyip Erdogan – hailed the Spanish court's decision.
“It would be terrible if, even on the other side of Europe, Turkey succeeded in having people who raise their voices against President Erdogan arrested,” said German Foreign Minister Sigmar Gabriel.
Gabriel, who had discussed the case with his Spanish counterpart Alfonso Dastis on Saturday, said he had “the utmost confidence” in the Spanish judiciary and that the government in Madrid “knows what this is about”.
Spanish police had on Saturday arrested Akhanli, who writes about Turkey's human rights record, while he was on holiday in Granada after receiving a so-called Interpol red notice, which is similar to an international arrest warrant.
Berlin quickly urged Madrid not to extradite Cologne-based Akhanli, who has previously been jailed in Turkey and was granted political asylum and citizenship in Germany.
Writing on Facebook, Akhanli's lawyer Ilias Uyar said his client was “being released from detention on condition he stays in Madrid” while Turkey starts the process of formally requesting his extradition.
“The battle was worth it,” the lawer wrote.
The case comes as relations between Turkey and Germany, home to three million ethnic Turks, have been badly strained, particularly in the wake of the failed coup against Erdogan a year ago and a subsequent crackdown on alleged plotters and enemies.
Gabriel last month vowed stinging measures hitting tourism and investment in Turkey and a full “overhaul” of troubled relations, accusing Erdogan of trying to muzzle “every critical voice” with mass arrests and sackings.
On Saturday, Erdogan hit out at Gabriel, saying “know your limits” after the minister vehemently criticised the Turkish leader for interfering in Germany's upcoming elections.
READ ALSO: 'Unprecedented interference' as Erdogan tells Turks in Germany not to vote for 'enemies of Turkey'
Turkey is holding several German citizens in custody, including Turkish-German journalist Deniz Yucel, the Istanbul correspondent of the Die Welt newspaper, who faces trial on terror charges.
Germany wants to prevent Akhanli from ending up behind bars in Turkey, where he was jailed from 1985 to 1987 before moving to Cologne in the 1990s and becoming a German citizen in 2001.
The Armenian question
Akhanli has written about the highly sensitive historical question of the mass killing of Armenians under the Ottoman Turkish empire.
Half a million to 1.5 million Armenians were killed between 1915 and 1917, in a bloodletting that Armenia and Western historians describe as genocide.
Turkey vehemently objects to the term, saying that 300,000 to 500,000 Armenians and as many Turks died in civil strife when Armenians rose up and sided with invading Russian troops.
Akhanli was arrested again in 2010 when he arrived at Istanbul airport for a visit, on charges he was allegedly involved in a 1989 armed robbery.
He was released four months later after being declared innocent, before an appeals court ordered new proceedings against him.
German Green MPs have taken up his cause, saying he is a victim of political persecution.