A gunman went on a rampage Friday in a busy shopping area of Munich, killing nine people and wounding 21 others in an act of “suspected terrorism” before he committed suicide, police said early Saturday.

The attack prompted authorities to lock down much of the southern German city and launch a massive manhunt. After the search ended, police said that the suspected gunman was an 18-year-old with dual German and Iranian citizenship who had been living in the city.

The motive for the attack, the Munich police chief said, was “fully unclear.”

The assault was the third act of carnage to shake Europe in eight days. It followed a July 14 attack by a Tunisian-born man who killed 84 people in the French Riviera city of Nice by plowing a truck into a crowd. On Monday, an Afghan teenager wielding an ax wounded five people on a train near the Bavarian city of Würzburg. In both those cases, the assailants were inspired by the Islamic State, authorities said.

But German officials said investigators were looking into the possibility that Friday’s attack was motivated by anti-immigrant sentiments, as well as the prospect that Islamist extremism was behind it.

Map: Where the Munich mall shooting happened

There were no immediate details about the victims of Friday’s attack on Munich’s Olympia shopping complex. Munich’s police chief, Hubertus Andrä, said 10 people were killed in total, including the shooter, who committed suicide about half a mile away from the mall. Sixteen of the 21 wounded were still being treated early Saturday at hospitals, police said.

About 50 people of various ethnic backgrounds gathered at a Munich sports hall early Saturday to await official word on the fate of missing loved ones.

Much of the city was placed on lockdown for hours as police conducted the manhunt. Despite initial reports of multiple attack sites, police could not confirm attacks in any other locations besides the shopping area. They initially thought as many as three assailants were involved, but later said two people who had been spotted speeding away from the crime scene were not connected to the bloodshed.

Officials did not immediately describe the full scope of the assault. But a senior security official told The Washington Post that four people were killed inside a McDonald’s restaurant near the complex and that one was fatally shot outside. The official said another victim died at a hospital.

The initial investigation was pointing “in all directions,” police spokesman Marcus da Gloria Martins told reporters in Munich.

There have been few mass shootings in recent years in Germany, which has tough gun laws, and police said they had not previously been aware of any threat posed by the gunman.

A shooting rampage in a Munich shopping area left at least eight people dead Friday. Police reported a ninth fatality and said they were trying to verify whether a gunman committed suicide. (Jason Aldag/The Washington Post)

Authorities were also investigating whether the gunman may have been motivated by anger at immigrants. Language against foreigners can be heard on a recording from the scene of the shooting, but it was not immediately clear who was speaking. A German television station said a witness told a colleague that the shooter shouted “Bloody foreigners!” at the scene of the McDonald’s attack. There was no immediate confirmation of that account.

A German intelligence official noted that it was the fifth anniversary of a lone-wolf massacre in Norway that claimed the lives of 77 people. The bomb and gun attacks there were carried out by a right-wing extremist.

As the manhunt was launched, helicopters fanned out over the city, and Munich’s transit system was shut down. Residents were asked to stay off the streets.

There was no immediate claim of responsibility for the rampage, but a high-ranking police official told The Post that it appeared likely that it was linked to terrorism.

A message posted online in Arabic, apparently from an Islamic State account, said: “Nowhere is safe for all of you. You people have opened the doors of hell by declaring war on us.”

An elite German counterterrorism force was promptly dispatched to Munich to help deal with the situation.

An employee inside the mall, who would give only her first name, Sabiha, said she saw a gunman open fire outside her clothing store. The assailant — described as about 6-foot-1, with black hair and a beard, and wearing a black shirt and “some kind of vest” — moved through the corridors before leaving the building, she told The Post.

Sabiha said she saw at least two people killed and one injured.

“I was lucky because he shot toward the other directions, not mine,” she said, speaking from a hiding spot inside a storage room in the store.

A video clip posted on Twitter showed a gunman opening fire outside the McDonald’s as people dashed for cover. The man appeared to fire on passersby with a handgun, seemingly at random.

A U.S. investment adviser and blogger, Eddy Elfenbein, tweeted Friday that his brother was in Munich. “He was helped to safety by a young Syrian immigrant. The young man’s family called from Aleppo to see if he was OK,” Elfenbein wrote.

In Washington, President Obama told a group of law enforcement officers at the White House that the United States is offering German authorities “all the support that they may need in dealing with these circumstances.”

He said the Munich attack is a reminder that “our freedoms, our ability to go about our business every day, raising our kids, seeing them grow up . . . that depends on law enforcement. It depends on the men and women in uniform every single day who are, under some of the most adverse circumstances imaginable at times, making sure to keep us safe.”

Republican presidential candidate Donald Trump said in a statement: “This cannot continue. The rise of terrorism threatens the way of life for all civilized people, and we must do everything in our power to keep it from our shores.”

The Munich mall is near the city’s Olympic Stadium, the centerpiece of the 1972 Summer Olympic Games that became known for tragedy when Palestinian terrorists took Israeli athletes hostage and killed 11 of them.

Munich is about 40 miles north of Germany’s southern border with Austria, and the city has been deeply affected by a huge influx of asylum seekers sparked by upheaval in the Middle East. More than 1 million asylum seekers arrived in Germany in 2015, and many of them have passed through Munich. About 1 in 7 of the arrivals remain in the city and surrounding region, in the state of Bavaria.

German security forces have been on heightened alert since Monday, when a 17-year-old Afghan armed with a knife and an ax attacked passengers on a commuter train near Würzburg. At least five people were injured. Police fatally shot the attacker as he tried to flee.

The Islamic State claimed responsibility for the train attack, but German authorities have said there is no evidence of direct links between the teen and the group.

Last month, German authorities arrested three Syrians on suspicion of planning an Islamic State attack on the city of Düsseldorf. The men had entered Germany with a wave of migrants fleeing war and mayhem in the Middle East.

The alleged plot involved suicide bombers, firearms and explosives, German authorities said. The arrests potentially thwarted a deadly operation comparable to assaults on Brussels in March and Paris in November.

Kirchner reported from Berlin and Branigin from Washington. Brian Murphy and Mark Berman in Washington contributed to this report.