BERLIN (AP) - The German government on Friday granted a Turkish request to allow the possible prosecution of a German TV comedian who wrote a crude poem about Turkey’s president, an awkward decision for Chancellor Angela Merkel as she seeks Ankara’s help in reducing Europe’s migrant influx.

Turkey demanded last week to have comedian Jan Boehmermann prosecuted for insulting a foreign head of state. German law required Merkel’s government to grant permission before prosecutors could consider whether to press charges.

Merkel stressed that it “means neither a prejudgment of the person affected nor a decision about the limits of freedom of art, the press and opinion.” She underlined the independence of the judiciary and the presumption of innocence.

She said her government had also decided that Germany’s law criminalizing insults of a foreign head of state is “dispensable in the future” and intends to repeal it, effective in 2018.

Merkel also expressed “great concern” about the state of media freedom and the fate of individual journalists in Turkey, as well as restrictions on the right to demonstrate, as she made her announcement in Berlin.

Boehmermann read the poem on ZDF television two weeks ago to illustrate what he said wouldn’t be allowed in Germany, contrasting it with another channel’s earlier satirical song that also poked fun at Turkish President Recep Tayyip Erdogan and angered Turkey.

ZDF withdrew the passage with the poem from its archives but argues that it didn’t break the law. Boehmermann’s ditty started by describing the Turkish leader as “stupid, cowardly and uptight” before descending into crude sexual references.

While the German government defended the earlier satirical song as legitimate free speech, it distanced itself from the poem, volunteering the opinion last week that it was “deliberately offensive.”

German officials have appeared at pains to avoid causing further friction with Erdogan, steering clear of direct criticism of the president in recent weeks amid Turkey’s sharp response to German satire.

That has generated criticism of Merkel, who has championed cooperation with Ankara to stem the migrant flow to Europe. Earlier this week, she said Germany’s desire to resolve the migrant crisis won’t change its commitment to free speech.

Merkel’s governing coalition was divided over the Turkish request. The Social Democrats, her junior coalition partners, wanted to reject it.

Justice Minister Heiko Maas, a Social Democrat, said this was the first such case in which the statement at stake was made by a journalist in a satirical program. “Freedom of opinion, the press and art are things requiring the highest protection under our constitution,” and that also needed to be taken into account, he said.

In its current form, the legislation involved dates from 1953. It derives from legislation drawn up in the late 19th century that outlawed insulting monarchs.

“The idea of lese-majeste no longer has a place in our criminal law,” Maas said.

The German Federation of Journalists said Merkel’s announcement sent “the wrong signal to the Turkish government.”

“That Erdogan’s arm now ultimately reaches to Germany, and via the chancellor, is unacceptable,” said Dietmar Bartsch, a top lawmaker with the opposition Left Party. He said Merkel’s credibility had been damaged.

Germany’s criminal code provides for up to three years in prison for insulting a foreign head of state. However, Alexander Thiele, a legal expert at the University of Goettingen, told n-tv television that even if Boehmermann is convicted, “one can assume that he faces a small fine at most.”

In addition to the request to have Boehmermann prosecuted for insulting a foreign head of state, Erdogan also has filed a criminal complaint against Boehmermann under a separate law, alleging slander.

Prosecutors in Mainz, where ZDF is based, are already examining the complaint.

Boehmermann’s lawyer, Christian Schertz, said that complaint made Friday’s decision to allow the comedian’s possible prosecution under the other legislation unnecessary. He noted that the poem was not broadcast alone, “but in the overall context of setting out what is allowed in Germany and what is not.”