Germany is considering a request from Turkey to prosecute a TV comedian who wrote a crude poem about the Turkish president, Chancellor Angela Merkel's spokesman said Monday.

The request poses an awkward choice for the German leader as she relies on Turkey to reduce the influx of migrants to Europe.

Turkey sent a diplomatic note making "a formal request for criminal prosecution" of comedian Jan Boehmermann, Merkel spokesman Steffen Seibert said.

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 satirical song that also poked fun at Turkish President Recep Tayyip Erdogan. Germany's ambassador was summoned to the foreign ministry in Ankara last month to hear a protest over that song.

While the German government defended the song as legitimate free speech, it has strongly distanced itself from the poem. Seibert has said that Merkel and Turkish Prime Minister Ahmet Davutoglu agreed the poem was "deliberately offensive."

Germany's criminal code provides for up to three years in prison or a fine for insulting a foreign head of state. However, it stipulates that such offenses are only prosecuted if the country in question seeks prosecution and the German government allows it.

Seibert told reporters Monday that officials would take several days to decide whether to allow prosecutors to proceed in the case, but stressed that Merkel holds free speech in high regard. It is "negotiable neither at home nor abroad," he said.

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. Merkel championed the European Union-Turkey deal for Ankara to take back migrants who travel illegally to Greece.

Seibert said he was stressing Merkel's dedication to free speech "to counter the impression that the freedom of opinion and art ... no longer has the necessary high value for the chancellor just because she, along with other Europeans, wants to resolve the refugee question in partnership with Turkey."

In Turkey, Erdogan spokesman Ibrahim Kalin said that "this kind of attack, including insults and rude statements to a country's president and also targeting a society, has nothing to do with freedom of expression or with press freedom."

"It is an insult everywhere in the world, and it is a crime," he said, adding that "those who publish this kind of ugliness ... apparently are annoyed with improved relations" between Germany and Turkey.

A senior German opposition lawmaker called on Merkel to reject the Turkish call for Boehmermann's prosecution.

Left Party parliamentary caucus leader Sahra Wagenknecht noted that in Turkey, more than 1,800 cases have been opened against people accused of insulting Erdogan since he came to office.

"If Merkel caves in in the Boehmermann case, he will be able to strike at will in Germany as well in the future," she said.