Turkey's President Recep Tayyip Erdogan has filed a legal complaint against a German comedian who recited a satirical poem about him - an incident that has created a diplomatic headache for Angela Merkel.

The move on Tuesday came as a pact between the European Union and Turkey, which involves refugee and so-called economic migrant swaps, was being implemented in attempt to stop the flow of people to Europe.

In a March 31 television programme, Jan Boehmermann, the host of the late-night Neo Magazin Royale programme on public broadcaster ZDF, recited the poem with references to bestiality and accusations that the Turkish leader repressed minorities and mistreated Kurds and Christians.

The poem, seemingly a deliberate provocation by Boehmermann, has exploded into a diplomatic incident that pits freedoms championed by Western Europe against recent moves in Turkey that many in the West see as an attempt to silence opposition voices.

Merkel, asked about the case on Tuesday, tried to separate the two issues and stressed her commitment to freedom of expression.

"Turkey is bearing a very big burden in relation to the Syrian civil war but all of that is completely separate from Germany's fundamental values ... freedom of the press, opinion and science apply and are completely separate from that," she told reporters.

2,000 cases opened

Under the German criminal code, Boehmermann could, if found guilty, be imprisoned for up to a year.

German media reported that Boehmermann had been placed under police protection and had cancelled the next episode of Neo Magazin Royale.

Prosecutors were conducting a parallel investigation into the comedian on suspicion of the more serious crime of "offending foreign states' organs and representatives", after Turkey made a formal request.

If he were found guilty of that offence, Boehmermann could face up to three years in prison.

For the second potentially more serious case to proceed, the German government would have to authorise prosecutors.

Berlin will decide on the request from Turkey in the coming days, Merkel said, adding that she cherished artistic freedom in Germany.

The law, though, which does not appear to exist in most other European countries, leaves Merkel with a conundrum.

If her government gives the nod to prosecutors, it could enrage Germans already dubious about what some view as a Faustian pact with Erdogan to help to stem the flow of refugees.

READ MORE: AK party is back on stage with force and responsibility

A poll by market research company YouGov showed that 54 percent of Germans opposed any investigation into Boehmermann by prosecutors, with only 6 percent in favour.

Yet if it rejects Ankara's request, Merkel could hurt relations with Turkey, a crucial partner in the refugee crisis and a candidate to join the EU.

Turkish prosecutors have opened nearly 2,000 cases against people for insulting Erdogan since he became president in 2014, the justice minister said last month.