The Munich shooter did not have a licence to own the gun, Bavaria's police chief said.
A Glock pistol was used in the attack, he added.
The shooter was in psychiatric and medical care, the Bavaria prosecutors' office spokesman said.
He had a book in his room about "rampage shooting in the mind", Bavaria's police chief said.
No suicide note has yet been found and his parents were unable to help police with the investigation due to shock, he added.
He was not known to police before the attack and had no criminal record.
Seven of the nine victims killed in Munich attack were teenagers, the police chief said.
The shooter had 300 bullets in his backpack, he added.
Four of the 27 injured have gunshot wounds.
Jeremy Corbyn has said he is "shocked" after the Munich shooting that left nine dead.
The Labour leader said: "Sympathy for the families and the bereaved and the people who have suffered a terrible shock because to see somebody shot in front of you is probably an image that will never go away."
Russian President Vladimir Putin has sent his condolences to German Chancellor Angela Merkel after Friday's deadly shooting in Munich, Russian news agencies have reported, citing the Kremlin.
Nine people were killed when gunman, who is believed an 18-year-old German-Iranian, opened fire near a busy shopping mall.
It was the third attack on civilians in western Europe in eight days.
Boris Johnson has offered his condolences to people in Munich after a gunman murdered nine people and injured 16 others before killing himself.
Foreign Secretary Boris Johnson said: "I am shocked and appalled by the terrible attack ...in Munich, and the loss of life.
"My thoughts are with those injured and the families of those killed. We stand ready to assist our friends in Germany."
Labour leader Jeremy Corbyn also tweeted support:
Shocking news from Munich - my thoughts are with the people of the city at this time
Flowers and candles have been laid near the scene of a deadly attack in Munich.
Nine people were killed in the attack at the Olympia shopping centre by the gunman, identified as an 18-year-old German Iranian, before he turned his gun on himself.
A 'game' was posted on Facebook offering free food at the McDonald's in Munich less than two hours before a gunman opened fire outside the restaurant, it has emerged.
In response to a question from reporter during a press conference, police chief Hubertus Andrae confirmed that officers were looking into whether the 'game', posted at 4pm on Friday, was an attempt to lure people to the scene ahead of the attack.
"[It is] one part of the comprehensive investigation we are conducting," he said.
A police cordon remained in place at the McDonald's this morning.
Police have carried out an early morning raid at an apartment in Munich after a gunman opened fire at a city shopping centre, killing nine people before turning the gun on himself.
The attacker, identified as an 18-year-old who had both German and Iranian nationality, was found dead in an alleyway near the Olympia shopping centre where the attack took place.
Police have said the motive for the attack is not yet clear, saying it was "too early" to say whether it was a terrorist attack or a "shooting rampage".
It was not immediately clear to whom the apartment searched by police belonged, but officers said they were looking for evidence in connection with the attack.
It is "too early" to tell whether a shooting at a Munich shopping centre was a terrorist attack or a "rampage," the city's police chief has said.
Hubertus Andrae said more would become clear as the investigation continues.
Nine people were killed when a gunman - identified as an 18-year-old German-Iranian - opened fire at the Olympia shopping centre on Friday evening.
The suspect was later found dead of a self-inflicted wound.
Mr Andrae said the motive for the attack was not yet clear.