BERLIN—German police on Thursday detained two Algerian men believed to be part of an Islamic State-linked group suspected of planning an attack in Berlin, in a sweep that included raids on refugee shelters and added to concerns that terrorists are posing as asylum seekers.

Among those arrested was a 35-year-old man in a shelter in the small town of Attendorn in western Germany, where he had been living since he entered the country posing as a Syrian refugee in December, a spokesman for the Berlin prosecutor’s office said.

...