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.
The attack, the authorities said, was carried out by a 43-year-old German who had posted a racist video and screed on the internet. He was later found dead from a gunshot, along with his mother, at his home, the authorities said, without identifying them.
His rampage took place in the heart of a region that prides itself on diversity and tolerance. The victims were not among the recent asylum seekers in Germany from places like Syria who have so angered the far right.
Rather, for the most part, they came from Turkish and Kurdish families that have lived in Germany for generations.
People of foreign descent in Hanau, a city of 95,000, often object to being called immigrants. In many cases, they are German citizens, born in Germany.
That was apparently the case for several of the victims, including one identified by relatives as Ferhat Unvar, 23, who had just finished training to be a heating system installer. Mr. Unvar, from a Kurdish family, had never visited his parents’ homeland, said Aydin Yilmaz, a cousin.
“It’s important to say that,” Mr. Yilmaz said. “He was born in Hanau. He’s a German. It was an act of terror against us all.”
“He had nothing against anyone,” Mr. Yilmaz said. “He just wanted to spend a nice evening with his friends.”
Mr. Yilmaz was among dozens of people who gathered Thursday afternoon at a Kurdish community center, a simple building across from a Harley-Davidson dealership on the outskirts of Hanau. Pictures of the victims were tacked to the wall. People drank strong tea from paper cups and talked quietly.
Mr. Unvar’s father was among them, looking gaunt with grief. Asked by a reporter if he wanted to say anything about his son, the father nodded affirmatively, but was then unable to speak. A woman standing next to him apologized, saying he was in too much shock.
Waves of “Gastarbeiter,” or guest workers, were brought to Germany in the 1950s and 1960s because of labor shortages, many of them from Turkey. Among them, Mr. Yilmaz said, was Mr. Unvar’s grandfather, who worked on paving crews, helping to build the streets that the perpetrator walked on.
Many people in western Germany have regarded right-wing sentiment as largely an eastern German phenomenon. When waves of Syrians refugees arrived in 2015, they were barely noticed in some western cities where there were already large minority communities.
In the aftermath of the attack, some residents wondered if the right-wing sentiment that had gripped other parts of the country had finally arrived here.
But Hanau has apparently long harbored right-wing sympathizers. In the last city elections, the far-right, anti-immigration Republikaner party received almost 10 percent of the votes.
That was even before the Alternative for Germany, or AfD, became the first far-right party to enter Parliament since World War II, in Germany’s last national elections in 2018.
“The AfD,” Mr. Kan said, “they’re the ones who are profiting from this hate.”
German politicians scrambled on Thursday to express their sorrow and horror at the attack, and to tamp down widening fears in Germany’s immigrant communities that they are endangered.
“Everything is being done to clarify the background of these horrible murders to the last detail,” Chancellor Angela Merkel told reporters in Berlin.
“Racism is a poison,” she said. “Hatred is a poison.”
Germany has some of the world’s strictest gun laws and last year moved to tighten them further, including requiring background checks, after a spike in shootings by right-wing extremists.
German authorities did not officially identify the gunman, in keeping with the country’s strict privacy laws. But the local authorities in Hanau said the gunman had a valid gun license.
It was issued to Tobias Rathjen, said an official from Main-Kinzig, the district that includes Hanau, who declined to be named because he was not authorized to disclose the information.
Terrorism experts and several German media outlets identified the shooter as Tobias R., whose photos matched the images of a man who posted a nearly two-minute screed on the YouTube page of a Tobias Rathjen, which has since been taken down.
Speaking in accented English, he addressed Americans, citing various conspiracy theories and calling on them to “Fight now.”
Why he addressed Americans and spoke in English remains a mystery, but it recalled the failed attempt to storm a synagogue in Halle on Yom Kippur last October. The gunman instead shot and killed a passer-by and a customer at a kebab shop.
Then, too, the attacker, a German, left a racist online diatribe in English, in what experts said was an attempt to broadcast his hate to a broader audience.
“The profiles of the all the attackers are uncannily similar,” said Peter Neumann, a professor of security studies at Kings College London. “All were socially isolated men who spent a lot of time online and had problems with women. They all cobbled their ideologies together in a do-it-yourself manifesto.”
The Hanau shootings add to an expanding number of far-right attacks in a political environment that has grown more aggressive with the AfD’s rise.
The number of far-right racist hate crimes surged from 2017 to 2018, to 1,664 from about 1,200, according to police statistics. The attacks — including stabbings, beatings, threats and harassment — targeted refugees, Jews and politicians or local representatives who voiced support for foreigners.
More recent figures have not been released yet, but violence and threats have continued.
In June, a conservative politician, Walter Lübcke, who had supported refugees, was fatally shot in the head. A man with neo-Nazi ties and a record of attacks on minorities confessed to the killing, which officials called the country’s first far-right political assassination since the Nazi era.
Security forces then revealed that Mr. Lübcke was one of many people on a neo-Nazi hit list.
The attack in Halle came less than four months later.
In the past three decades, the German population has grown increasingly diverse, leading to bitter dispute over who qualifies as German and who is still considered a “foreigner.” Roughly a quarter of Germany’s nearly 82 million people are immigrants or descendants of immigrants.
The conflict over the country’s cultural identity spilled into the streets in the eastern city of Chemnitz in August 2018, when Germans flashing Nazi salutes chased down people they thought looked like immigrants.
The Hanau shootings have deepened the sense of insecurity among minority groups, leaving them frustrated at what they regard as a tepid government response to the growing strength of right-wing movements.
“We would like to see the government take more decisive action against right-wing extremism,” said Mehmet Tanriverdi, vice chair of the Kurdish Community in Germany, who visited the scene of the shooting Thursday.
A few minutes later, sirens and the rumble of police motorcycles drowned out his words, as a motorcade arrived carrying Horst Seehofer, the German interior minister, one of numerous political leaders who swept into Hanau to offer condolences.
As Mr. Seehofer spoke to reporters in front of the Midnight bar, a man in the crowd shouted, “It’s all just theater!”
Earlier, state lawmakers gathered to hold a moment of silence for the victims before canceling their planned session, and flags on public buildings across the state were ordered lowered to half-staff.
Claus Kaminsky, the mayor of Hanau, called the attack ‘‘one of the most bitter hours in our peacetime history.”
“We will do everything humanly possible to defend our shared solidarity,’’ he said. ‘‘We will not allow it to be destroyed.”
Citizens, too, were anxious to show that the vast majority remains tolerant. In the early evening, throngs of residents streamed toward the city’s market square for a demonstration of solidarity, many carrying homemade signs. Across the street from the Midnight bar, people left flowers or lit candles.
But expressions of sympathy and solidarity did not go far in appeasing anxieties.
Farak Demir, who described himself as a friend of one victim, said that Hanau’s ethnic and religious groups generally treat each other with respect. But he was also among those suddenly wondering whether that sentiment was as widespread as he had thought.
“We have no security, foreigners in Germany,” he said. “It happens again and again.”
Jack Ewing reported from Hanau, and Melissa Eddy from Berlin. Christopher F. Schuetze contributed reporting from Hanau and Tiffany May and Austin Ramzy from Hong Kong.