He was also a victim of bullying who suffered from panic attacks set off by contacts with other people, investigators said, adding that he had planned the attack for a year.
Law enforcement officials piecing together a portrait of the 18-year-old shooter said he was seeing a doctor up to last month for treatment of depression and psychiatric problems that began in 2015 with inpatient hospital care followed by outpatient visits.
They said medication for his problems had been found his room. But toxicological and autopsy results were still not available, so it's not yet clear whether he was taking the medicine when he went on his shooting spree Friday, killing nine people and leaving dozens wounded.
Investigators said the Munich shooter had researched that slaughter online and had visited the site of a previous school shooting in the German town of Winnenden last year.
"He had been planning this crime since last summer," said Robert Heimberger, Bavaria's top official, citing a "manifesto" linked to the shooting found in the gunman's locked room in the apartment he shared with his parents and brother.
Heimberger said he could not reveal details of the document yet because there were "many more terabytes" of information to evaluate, but described the gunman as a "devoted player" of group internet "killer games" pitting virtual shooters against each other.
Weapons are strictly controlled in Germany and police are still trying to determine exactly how the shooter obtained the Glock 17 used in the attack.
Heimberger said it's "very likely" the suspect purchased the weapon illegally online on the "darknet," a restricted access computer network often used by criminals. He said the weapon had been rendered unusable and sold as a prop before being restored to its original function.
Police said they had taken in a friend of the shooter for questioning, who might have known of the attack plan. Further details were not immediately available, but Germany's dpa news agency reported the 16-year-old boy had gone to police himself after the act.
Some 1,500 people gathered at the scene of the shooting Sunday evening, lighting candles and placing flowers in tribute to the victims.
The attack Friday took place on the fifth anniversary of the killing of 77 people by Norwegian right-wing extremist Anders Behring Breivik, whose victims included dozens of young people.
The shooter's father saw a video of the start of his son's rampage on social media and went to police as it was taking place, Heimberger said, adding that the family was still emotionally not up to questioning by police.
Witnesses say the gunman shouted slurs against foreigners, even though he himself was the German-born son of Iranian asylum-seekers
Heimberger said the McDonald's restaurant were most of the victims died was a hangout for youths of immigrant backgrounds, and the dead included victims of Hungarian, Turkish, Greek, and Kosovo Albanian backgrounds and a stateless person. The restaurant remained cordoned off Sunday, as people gathered for a second day to pay their respects.
Across the street, at the shopping mall where the rampage spilled over, the pavement was covered by a long line of flowers, some with messages of condolences. One woman, dressed in black, knelt and cried before being escorted away by an acquaintance.
"Today, I feel deep sadness," said Veljo Raicevic, a resident. "Why can one person do something like this?"
Fatu Sherrit Schmidt was among those visiting the site.
"Some of the kids who died happened to be my son's friends," she said. As for the shooter, "his younger brother was at my son's birthday two years ago."
In Greece, the residents of Aratos, a village of 700 near the northeastern city of Komotini, were in mourning. They had expected 17-year-old Hussein Daitzik and his family, migrants living in Germany, to visit next week as part of their annual vacation in their ancestral home. Instead, now they will attend Hussein's funeral
Daitzik died trying to take his sister Gulfer " they and a brother, Sunai, were triplets " out of the line of fire, says village mayor Amet Amet. She was not wounded.
"He had many friends here in the village," Amet said.
In the aftermath of the attack, Bavaria's top security official urged the government to allow the country's military to be deployed in support of police during attacks. Because of the excesses of the Nazi era, Germany's post-war constitution only allows the military, known as the Bundeswehr, to be deployed domestically in cases of national emergency.
But state Interior Minister Joachim Herrmann told the Welt am Sonntag newspaper that the regulations are now obsolete and that Germans have a "right to safety."
"It would be completely incomprehensible ... if we had a terrorist situation like Brussels in Frankfurt, Stuttgart or Munich and we were not permitted to call in the well-trained forces of the Bundeswehr," he said.
Federal Interior Minister Thomas de Maiziere backed the idea and suggested that it might be possible without constitutional changes.
Munich deployed 2,300 police officers to lock down the city Friday night, calling in elite SWAT teams from around the country and neighboring Austria.