The gunman who shot nine people dead in Munich was a mentally ill 18-year-old who felt bullied by his peers and had threatened to kill his classmates only months before the attack. German police are investigating the possibility that David Ali Sonboly targeted young people, luring victims to the site of the rampage through a fake Facebook posting.

Seven teenagers were among the dead, the youngest a 14-year-old girl. Sonboly opened fire at a McDonald's in the southern German city before storming Olympia shopping centre across the street on the evening of 22 July.

Earlier that day he is believed to have hacked the Facebook account of a young Turkish woman to post a message claiming freebies would be offered at the fast-food restaurant.

"I'll give you some treats if you want, but nothing too expensive," the posting read.

German Interior Minister Thomas de Maiziere said police were looking into reports that the teen, who underwent psychiatric treatment for depression, was bullied by his peers and plotted a revenge attack. The attack came hours after Sonboly told his parents he had failed his end-of-school exam for the second time.

A classmate reportedly said that a few months earlier the attacker had yelled at schoolmates: "I will kill you all," after a quarrel. Sonboly referred to the fact that he had been "bullied for seven years" in a heated exchange with an onlooker during the attack that was captured on camera.

He also yelled anti-foreigner slurs and authorities said they were investigating whether hatred towards foreigners was also a motive. Despite being born in Germany to Iranian parents, Sonboly reportedly idolised Norwegian mass murderer Anders Breivik, a far-right extremist.

The killing came on the fifth anniversary of the Breivik's massacre. Sonboly's gun, a Glock pistol, was the same type as used by Breivik during the 2011 massacre on the Norweigan island of Utøya.

Munich police quickly established that the teenager, who killed himself as police closed in, did not have any links with any Islamist or terror groups. However, Islamic State (Isis) did praise his attack.

Munich Shooting
A woman lays flowers in front of the Olympia shopping mall, where yesterday's shooting rampage started, in Munich, GermanyReuters