CELLE, Germany — An immigrant from Iran, Mehdi Hushmand was a beloved high school science teacher known for his devotion, and for going out of his way to help settle some of Germany’s newer immigrants — the more than one million migrants and refugees who arrived en masse last year.

So it was a big deal here in Celle when Mr. Hushmand was found bludgeoned to death in the basement of his home in February. But the shock was bigger still when the prime suspect turned out to be a recently arrived migrant from Afghanistan whom he had befriended.

News of the murder and the still murky motive behind it have unsettled this orderly town of about 70,000 in the German heartland near Hanover, with its quaint timbered buildings and proud history as an ancestral home of the Windsor nobles who became Britain’s royal family.

But it has also tapped into Germany’s larger, naggingly uncomfortable relationship with migration — its sometimes strange and unfamiliar story lines, its quiet successes and potential perils — at a moment when the country is struggling to integrate its new arrivals.