The teenage killer who went on a deadly shooting rampage in Munich had been planning the attack for more than a year and over that period spent two months in a clinic for psychiatric treatment, German authorities said. David Ali Sonboly, 18, opened fire with a Glock pistol at a McDonald's and the Olympia shopping centre in the Bavarian city on 22 July, killing nine people and wounding at least 27 before killing himself.

"He had been planning this crime since last summer," Bavarian investigator Robert Heimberger told a press conference. Detectives said the teen, who had a passion for shoot first-person shooter video games, had researched previous mass murders.

In 2015, he travelled 250km (155.3 miles) from Munich to visit a school in the town of Winnenden, the site of a school shootings that saw 17 people killed, and took photographs.

Six years earlier, another teenager, 17-year-old Tim Kretschmer, had stormed the educational institute armed with his father's gun and shot dead nine students and three teachers before moving to a nearby car dealership where he killed another two people. Just like Sonboly, Kretschmer turned the weapon on himself as police closed in.

In 2015, Sonboly had also received inpatient treatment for mental issues, according to the Munich prosecutors' office. Prosecutor Thomas Steinkraus-Koch said the shooter "had fears of contact with others" and depression and received also outpatient care after spending two months in a clinic.

Steinkraus-Koch added police had not found any evidence so far suggesting Sonboly had any political motivation for the attack and he seemed to have chosen his victims at random. Earlier authorities said they were probing reports that the gunman deliberately targeted youths in a revenge attack after years of bullying and harboured hatred against foreigners.

The incident has prompted calls by German politicians to tighten the country's already strict gun laws. "We need to do everything further possible to curb the access to deadly weapons and strictly control them," Vice Chancellor Sigmar Gabriel told newsgroup Funke Mediengruppe in an interview.

Sonboly appeared to have acquired the Glock gun used in the killings illegally online on the so-called "dark net", according to Heimberger. The weapon's serial number had been removed.

Munich shooting
President of the Bavarian State Office of Criminal Investigation Robert Heimberger and Senior Prosecutor Thomas Steinkraus-Koch attend a news conference after a shooting rampage at the Olympia shopping mall in MunichReuters