BERLIN — German Chancellor Angela Merkel on Thursday condemned the "poison" of racism in the country after a gunman, apparently fueled by extremist right-wing views and conspiracy theories, killed nine people in two ­hookah bars.

The Wednesday night attack in the town of Hanau, about 15 miles east of Frankfurt, left Germany reeling as it grapples with a far-right resurgence. It marked the deadliest mass shooting in the country since a gunman killed nine people in Munich in 2016.

In a televised speech, Merkel said that while it was too early for a final assessment of the shooting, there were many indications that the gunman acted with extremist right-wing, racist motives.

"Racism is a poison; hate is a poison," Merkel said. "This poison exists in our society, and it's to blame for too many tragic events."

The shooting sites appeared to have been targeted because of their clientele. The two establishments, where people gather to smoke water pipes known as ­hookahs, are popular with patrons of Middle Eastern origin.

Of the people killed, five held Turkish citizenship, Turkey's state news agency Anadolu reported, citing Ankara's ambassador to Berlin. Prosecutors said the victims included German and foreign nationals between the ages of 21 and 44.

The Hanau attack followed several violent incidents with links to the far right over the past year. In June, a politician known as a vocal supporter of asylum seekers was shot dead. In October, a shooter tried to attack a synagogue in the eastern city of Halle on Yom Kippur, turning his homemade weapon on passersby and a nearby kebab shop after he failed to gain entry. He killed two people.

German authorities said they have stepped up their monitoring of far-right groups. Last week, police raids resulted in the arrest of 12 members of such a group suspected of planning attacks on mosques and targets associated with refugees and asylum seekers. The alleged plots seemed to draw inspiration from last year’s mosque attacks in Christchurch, New Zealand, that killed more than 50 people.

But German security officials say lone-wolf attackers are particularly challenging to track and are often unknown to authorities until it is too late.

The suspect in Wednesday’s shooting was identified as Tobias Rathjen, 43, who authorities said was a licensed gun-holder.

Not long after the twin attacks, authorities said the suspect had been found dead in his home alongside his 72-year-old mother. His father was outside and unharmed, prosecutors said.

Authorities said they were investigating whether Rathjen had ties to any organized groups, but police said they were not searching for further suspects.

In a grimly familiar pattern, Rathjen appears to have posted videos and documents espousing his views, thick with conspiracy theories and rants against immigrants. “Not everyone who has a German passport is purebred and valuable,” reads one document posted on a website under Rathjen’s name. “I can imagine cutting the population in half.”

The International Center for the Study of Radicalization (ICSR) at King’s College London said it has confirmed the authenticity of the document and others on the site, which included rambling missives about “strategies” for combat operations in Iraq and Afghanistan, and about the German soccer association.

A senior German security official said a video posted online last week is being investigated, as it is thought to show the suspect. In it, a man addresses the camera in what he says is a “message” to Americans. “Your country is under control of invisible secret societies,” he says, warning about “mind control” and the “mainstream media.” He calls on U.S. citizens to “fight now.”

A second video, shared by the ICSR, shows a man speaking to the camera in the same bedroom. He mixes far-right conspiracy theories on the white race being “replaced” with other contentions.

“One part of the video contains some traditional far-right narratives around race and immigration, but in the other half the attacker goes into much more ­surreal and less tangible conspiracy theories,” the ICSR said. “Overall, he is very paranoid and delusional.”

He ends with “Wahrheit macht frei,” meaning “The truth sets you free” but also an allusion to the Nazi slogan on the gates of the Auschwitz death camp, “Arbeit macht frei,” or “Work sets you free.”

It was about 10 p.m. that a gunman opened fire on patrons at Midnight, a hookah bar in central Hanau. Police said the shooter sped off in a dark vehicle before targeting a second venue, Arena Bar and Cafe.

A man identified as Iskander M by the Turkish television channel that interviewed him said he heard shots outside before an attacker entered the cafe and started shooting everyone in sight.

The man said that he was shot in the shoulder and that customers piled on the floor in a panic. “The boy underneath me had a bullet hole in his neck,” he said. “He told me, ‘I can’t breathe, and I can’t feel my tongue.’ I told him he should say a prayer, which is what he did.”

Souad Mekhennet in Washington contributed to this report.