By Noah Barkin and Michelle Martin
BERLIN (Reuters) - Germany's Angela Merkel agreed on Friday to allow prosecutors to pursue a case against a German comedian who mocked Turkey's President Tayyip Erdogan, prompting accusations that she had failed to protect free speech and dividing her ruling coalition.
Erdogan had demanded that Germany press charges against Jan Boehmermann after he recited a poem about the Turkish leader in a show on German public broadcaster ZDF on March 31, suggesting he hits girls, watches child pornography and engages in bestiality.
A section of the German criminal code prohibits insults against foreign leaders but leaves it to the government to decide whether to authorize prosecutors to pursue such cases.
This put Merkel in an awkward position. She has been the driving force behind a controversial European Union deal with Turkey to stem the flow of refugees into Europe and critics have already accused her of ignoring violations of human rights and press freedoms in Turkey to secure its cooperation.
The chancellor made clear in a statement that the decision to allow prosecutors to investigate was not a verdict on the merits of the case itself.
But she came under fire from the Social Democrats (SPD), her center-left coalition partner, which had wanted the Turkish request to be rejected. With her cabinet split on the matter, Merkel had the casting vote.
"We are of the view that the authorization for prosecution ... should not have been granted," Foreign Minister Frank-Walter Steinmeier and Justice Minister Heiko Maas, both Social Democrats, said in a joint statement.
Boehmermann's lawyer, Christian Schertz, said Merkel's decision was "completely unnecessary", noting that Erdogan had already filed a separate legal complaint against Boehmermann.
Presenting her decision in a televised statement, Merkel said: "Turkey is a country with which Germany has close and friendly ties."
Several Turkish officials declined to comment and Erdogan did not broach the subject at a speech in Istanbul on Friday. One senior Turkish official said: "We want to see the result of this case and don't want to say anything about it at this stage."
But Omer Celik, spokesman for Turkey's ruling AK party, defended Merkel's decision.
"Without a doubt this is the right decision," Celik told broadcaster TRT Haber on Friday. "This is an insult against our nation and state. That person's statements on that television channel were not criticism but direct insult."
Kai Diekmann, publisher of Germany's mass-selling daily newspaper Bild, responded with a commentary under the headline "In Erdogan's Hand" in which he asked: "Has Germany, with the Turkey deal, made itself susceptible to blackmail?"
Diekmann added: "When (the chancellor) travels to Turkey next week, she must say to her host's face how terrible things are in Turkey with freedom of opinion and of the press."
Merkel travels to Turkey with top EU officials on April 23.
Sahra Wagenknecht, of the far-left Linke party, accused Merkel of kowtowing to the "Turkish despot" Erdogan.
Boehmermann, an impish-looking 35-year-old, is known for pushing the boundaries of satire. Last year he claimed to have manipulated a video of Greece's then-finance minister Yanis Varoufakis, in which he is shown giving the middle finger -- known as the "Stinkefinger" in German -- to Berlin for its tough stance on the debt crisis. The video infuriated German politicians.
The cult comedian made clear before reciting the poem about Erdogan that he was intentionally going beyond what German law allowed.
ZDF has since removed a video of the poem from its website. But Boehmermann has received backing from prominent German artists while 82 percent of people polled by Focus magazine viewed the poem as defensible.
The comedian is reportedly under police protection and canceled his last show on ZDF.
In giving her statement, Merkel pressed Turkey -- a candidate for European Union membership -- to uphold the values of freedom of expression, the press and art.
She also made reference to the three million people with Turkish roots who live in Germany, the strong economic ties between the countries and their cooperation as NATO allies.
But the Association of German Journalists (DJV) said Merkel had sent the "wrong signal" to the Turkish government even though she made reference to violations of the right to freedom of press and opinion in Turkey.
A Turkish group called the Union of European Turkish Democrats, which has posted videos online supporting Erdogan, filed a complaint with Austria's media watchdog on Friday over newspaper Oesterreich's reprinting of parts of Boehmermann's poem.
Merkel said the German government plans to remove the section of the criminal code that requires it to grant permission for prosecution in such cases.
(Additional reporting by Caroline Copley and Holger Hansen in Berlin, Shadia Nasralla in Vienna and Orhan Coskun in Ankara; Writing by Michelle Martin, Noah Barkin, and Paul Carrel; Editing by Mark Heinrich and David Goodman)