Cologne police cordoned off a large area around the mosque for safety reasons (AFP)
Turkish President Recep Tayyip Erdogan has opened one of Europe's largest mosques in Cologne as he wrapped up a controversial visit to Germany, with police deploying in force to manage rival rallies in the city.
Saturday's official inauguration marked the closing event of his three-day state visit, aimed at repairing frayed ties with Berlin after two years of tensions.
Erdogan left the German capital after a breakfast meeting with German chancellor Angela Merkel, their second talks in two days. While both leaders signalled their interest in a cautious rapprochement, Merkel stressed that "deep differences" remained on civil rights and other issues.
During a news conference between the two leaders on Friday, a participant wearing a T-shirt with the slogan "Freedom for Journalists" was bustled out when he tried to shout Erdogan down.
Erdogan then travelled to the western city of Cologne where several thousand critics took to the streets, protesting everything from Turkey's record on human rights and press freedom to its treatment of minority Kurds.
On the bank of the Rhine, demonstrators waved banners reading: "Erdogan not welcome."
Cansu, a 30-year-old student of Turkish origin who came from Switzerland to join the protest, said: "I want to be the voice of people who can't take to the streets in Turkey.
"Because they have been arrested, killed or otherwise suppressed. Erdogan thinks anything that differs from his opinion is terrorism."
Tomas, a German student, turned up in a white suit splattered with fake blood. He and several others carried a giant banner that read "Dictator. Mass murderer".
"We are here to show Cologne does not want you," the 22-year-old said.
'He has done a lot for his people'
Erdogan supporters meanwhile gathered at the Cologne Central Mosque, an imposing dome-shaped building commissioned by the Turkish-controlled Ditib organisation.
Cologne police cordoned off a large area around the mosque for safety reasons, but thousands of Erdogan supporters spilled into closed-off side streets, eager for a glimpse of the Turkish leader.
Many waved Turkey's red and white flag or held up pictures of Erdogan, with the crowd occasionally breaking into cheerful chants of "Who is the greatest? Turkey!"
"Erdogan is very popular because he has done a lot for his people," said Yusuf Simsek, 42, a computer technician with Turkish roots.
Semra, a 41-year-old kitchen worker, agreed.
The mosque is designed to resemble a flower bud opening (Reuters)
"I don't care about the criticism. He's doing everything that's right for Turkey and we are fully behind him."
Both Cologne Mayor Henriette Reker and the state's premier Armin Laschet declined to attend the mosque ceremony.
The snubs echoed the lukewarm welcome the Turkish leader received at a state dinner on Friday evening hosted by German President Frank-Walter Steinmeier, which several opposition politicians boycotted. Merkel also skipped the banquet, the AFP news agency reported.
Ties between the two NATO countries soured after Berlin criticised Ankara's crackdown on opponents following a failed 2016 coup, which saw tens of thousands arrested.
Tensions eased somewhat after several high-profile German-Turkish nationals were released this year, but five remain behind bars.
Merkel, whose country is home to more than three million ethnic Turks, stressed the need for continued dialogue to overcome disagreements. But she also highlighted Germany's interest in a "stable" Turkey, which she relies on to help stem the flow of migrants to Europe.
Erdogan, seeking international allies as he spars with US President Donald Trump, and with the Turkish economy in turmoil, likewise struck a conciliatory tone.
But he also pressed Germany to take stronger action against "terrorists" like supporters of the Kurdistan Workers' Party (PKK) or followers of Fethullah Gulen, whom he blames for the coup attempt. Gulen, a US-based cleric, denies involvement.
"We take very seriously the evidence Turkey provided," Merkel told Friday's news conference, the Reuters news agency reported, but said Germany needed more evidence to declare Gulen's movement an illegal group as Ankara demands.
Cologne is located in North Rhine-Westphalia state which is home to significant numbers of ethnic Turks, many of whom moved to Germany as so-called "guest workers" from the 1960s.
The giant Cologne Central Mosque finally opened its doors in 2017 after eight years of construction and budget overruns. The size of the building, designed to resemble a flower bud opening, and its two towering minarets has disgruntled some locals, triggering occasional protests.
The Turkish-Islamic Union of the Institute for Religion (Ditib) that commissioned the glass and cement structure is itself not without controversy. The group runs hundreds of mosques across Germany with imams paid by the Turkish state.
Known for its close ties to Ankara, it has increasingly come under scrutiny with some of its members suspected of spying on Turkish dissidents living in Germany.