BERLIN (Reuters) - German President Joachim Gauck joined a Ramadan dinner on Monday, warning against demonizing Muslims a day after a man pledging allegiance to Islamic State shot dead 49 people in a U.S. nightclub.

German President Joachim Gauck gives a press statement at the presidential residence Bellevue Palace in Berlin, Germany, June 6, 2016. REUTERS/Hannibal Hanschke

Germany is at the front line of efforts to integrate migrants into Europe after more than 1 million arrived there last year, most of them Muslims fleeing war and poverty in the Middle East, Africa and elsewhere.

The influx has raised tensions in German society. Refugee shelters have been attacked and the anti-immigration Alternative for Germany (AfD) party has become a political force, describing Islam as incompatible with the constitution and calling for a ban on minarets and the burqa.

Gauck, a former Lutheran pastor from East Germany, joined an iftar dinner to break the Ramadan fast in Moabit, a poor district of Berlin with a large migrant population.

The Muslim holy month revolves around daily fasts from sunrise to sunset, and then favorite meals with family and friends during the night hours.

“Promoting encounters is particularly important at a time when mutual mistrust is spreading,” Gauck said, according to an advance text of his speech. He said many Germans were anxious after recent Islamist attacks in Paris and Brussels.

“And for some, the fear of Islamist terrorism has become a fear of Muslims,” Gauck said. He warned against a polarization of society and urged Germans to seek regular encounters with Muslims in their neighborhoods.

Gauck said that integration efforts in Germany were paying off and a growing number of Muslims were speaking out against fundamentalist interpretations of the Koran.

“All who celebrate the iftar together today can attest: Living together is possible,” Gauck said.

“Simply being together can sometimes even replace long discussions - especially if we let ourselves be guided by the golden rule that is common to all major religions and simply says: Treat others as you want them to treat you.”