He had been bullied at more than one school. He played violent video games, and developed a fascination with mass shootings. He kept a copy of the German edition of “Why Kids Kill: Inside the Minds of School Shooters,” a study by an American academic psychologist, and he was treated for psychiatric problems.

Somewhere along the way, Ali Sonboly got his hands on a 9-millimeter Glock handgun, and hundreds of rounds of ammunition for it. And at 5:52 p.m. on Friday, at a McDonald’s in Munich a few miles from where he lived with his mother, father and brother, he started shooting.

Mr. Sonboly, 18, moved on to a shopping mall across the street, then to the top level of an adjacent parking garage. By the time his rampage was done, he had killed eight other young people and one middle-aged person. Then, in front of two police officers, he killed himself with his own gun, the police said.

It was the third mass attack in Europe in little over a week, after the killings of 84 people in Nice, France, and an attack by a young refugee wielding an ax and a knife in Germany that left five people wounded.