BERLIN—German police detained an asylum seeker suspected of plotting an attack for Islamic State, the federal prosecutor’s office said Thursday, the latest evidence of a mounting terror threat posed by the arrival last year of hundreds of thousands of migrants into the country.

The 27-year-old man, identified by federal prosecutors as Ashraf Al-T., allegedly received approval from an ISIS operative in Syria to carry out an attack on...