Turkish President Tayyip Erdogan has filed a complaint against a comedian who recited a satirical and sexually crude poem about him on German television, complicating Berlin's attempts to get Turkey's help in dealing with Europe's migrant crisis.

The issue pits freedom of speech values that are core to western Europe against recent moves in Turkey by Erdogan that critics say crack down on dissent.

The public prosecutor's office in the western city of Mainz said Erdogan had filed the complaint via lawyers against Jan Boehmermann for insulting him. Boehmermann is the host of the late-night "Neo Magazin Royale" on the public ZDF channel.

In a programme broadcast on March 31, Boehmermann recited a poem about Erdogan that included references to the president enjoying sex with sheep and goats and accused him of "kicking Kurds and slapping Christians while watching child porn."

Before reading it, Boehmermann referred to a satirical song called "Erdowie, Erdowo, Erdogan" broadcast on NDR television late last month that depicted Erdogan as an egotistical, thin-skinned authoritarian bent on suppressing anything that offends him.

That show led Turkey to call in Germany's envoy to provide an explanation and demanded the video be deleted. However Germany rejected Turkish protests and the attempts to suppress the musical number backfired spectacularly. Its authors added English and Turkish subtitles and the YouTube video, which had been little viewed before, has now been watched almost seven million times.

Boehmermann said the NDR broadcast fell under the right to artistic freedom, press freedom and freedom of opinion but that his poem probably would not, describing it as an example of impermissible "abusive criticism." A man posing as a lawyer appeared alongside him during the broadcast to advise him the poem would not qualify as satire.

ZDF have now pulled the video from the internet, prompting the television host to tweet that they had shown the "limits of satire" in Germany.

Prosecutors said Erdogan's complaint would be examined as part of a pending procedure. They had already begun investigating Boehmermann on suspicion of the crime of "offending foreign states' organs and representatives" after more than 20 people filed complaints.

On Monday, Chancellor Angela Merkel's spokesman said Berlin was examining a formal request made by Turkey for it to prosecute Boehmermann and a decision would be made in the next days.

Merkel, who has spearheaded EU efforts to secure Turkey's help in dealing with Europe's migrant crisis, has told Turkish Prime Minister Ahmet Davutoglu in a telephone conversation that the poem was "deliberately offensive", in an apparent attempt to defuse the situation.

If the government decides to decline the Turkish request to prosecute Boehmermann, she risks a worsening of diplomatic relations with Turkey, Wolfgang Kubicki, senior member of Germany's business-friendly FDP party, told NDR radio.

"If the government were to support the move, there would be a huge backlash domestically," he said, adding that in his opinion as a trained lawyer the poem was "distasteful" but within the limits of artistic freedom.

Freedom of speech has been deteriorating drastically in Turkey in recent years. Dozens of journalists have been jailed — including three members of VICE News staff last year, who were ultimately released — alongside dissident activists and bloggers. Last month, the government took control of the main opposition newspaper and an opposition news agency.

During his time as prime minister, Erdogan brought a raft of defamation cases against writers and intellectuals for criticizing him and his policies; since he assumed the presidency in 2013 he's been doing the same against members of the Turkish public who have used their social media accounts to lambast him.