The German government has granted a request from Turkey to allow the possible prosecution of a German TV comedian who wrote a crude poem about its president.

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

Merkel stressed on Friday 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.

Germany's anti-refugee party surges in regional elections

She said her government also decided that Germany's law criminalising 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.

The decision comes at an awkward time, as Merkel is seeking Ankara's help in reducing Europe's refugee influx.

Uli Bruckner, a professor in European studies at the Stanford University Berlin, said Merkel appeared "relatively stressed" during Friday's announcement.

Bruckner said the decision to allow prosecution sends signals both internally and externally that the government is taking the case seriously.

"First of all, it's a commitment to Turkey as a friend of Germany," he told Al Jazeera. "Secondly, it's a commitment to what Germany stands for as human rights, the freedom of speech and the independence of the courts.

"All this was put together in a statement that was very short and very concise."

'Deliberately offensive'

Boehmermann read the poem on ZDF television two weeks ago to illustrate what he said would not 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 of the poem from its online archives but argues it did not break the law.

WATCH: Erdogan vs Gulen - Behind Turkey's media crackdown

Boehmermann's piece started by describing the Turkish leader as "stupid, cowardly and uptight" before descending into crude sexual references.

After officials removed Boehmermann's clip from the internet, the comedian said he and ZDF had "demonstrated the limits of satire in Germany - finally!"

Merkel's governing coalition was divided over the Turkish request. The Social Democrats, her junior coalition partners, had advocated rejecting it.

The German Federation of Journalists said Merkel's announcement sent "the wrong signal to the Turkish government", while anti-censorship activists criticised the move.

"There are cases in Germany of media freedom violations ... but this case is quite an anomaly because it comes from the very top," Melody Patry, a campaigner for the free speech advocacy group Index on Censorship, told Al Jazeera.

"In Turkey, it is very frequent to have the authorities suing journalists, or trying to silence journalists - coming from Germany, and having the government to authorise the prosecution on behalf of another head of state for a comedy, that is unprecedented."

Germany's criminal code provides for up to three years in prison for insulting a foreign head of state.