HANAU, Germany — Hanau, a small city in western Germany, considered itself a melting pot, an island of tolerance. That was before a racist extremist opened fire at a hookah bar Wednesday night, killing nine mostly young people in Germany’s worst attack in recent memory.

A working-class community just outside Frankfurt, Hanau was ethnically diverse long before the issue of immigration began tearing apart German politics with the arrival of nearly a million asylum seekers five years ago.

“We have lived very peacefully together,” said Metin Kan, a 43-year-old of Turkish descent, who said he was a friend of one of the victims, the owner of the Midnight bar.

The attack Wednesday did more than shock Germany. It drove home a fear that no part of the country is immune to the potential for violence that has been unleashed with the rise of a far right angered by Germany’s changing society.