Police searched for attackers, thinking there might be three, and found a man who had killed himself on a side street near Olympia shopping mall, police Chief Hubertus Andrae said.
Based on surveillance video and witness statements, police concluded he was the sole gunman, Andrae said.
The unidentified attacker was an 18-year-old German-Iranian who had lived in Munich for at least two years.
The man was not known to police and his motives are unclear, authorities said. No group has claimed responsibility.
Many children were among the casualties.
The shooting comes as recent terrorist attacks have put Europe on high alert.
This week, a teenager who said he was inspired by ISIS stabbed passengers on a German train
before police shot him dead. Eight days earlier, 84 people were killed when a man drove a large truck through a crowd celebrating Bastille Day in Nice, France.
Children unable to run away
The gunman in Munich started shooting at a McDonald's across from the Olympia mall around 5:50 p.m. (11:50 a.m. ET), Andrae said.
A witness who wanted to be identified only by her first name, Lauretta, told CNN her son was in the bathroom with a shooter at the restaurant.
"That's where he loaded his weapon," she said. "I hear like an alarm and boom, boom, boom ... and he's still killing the children. The children were sitting to eat. They can't run."
Lauretta said she heard the gunman say, "Allahu Akbar," or "God is great" in Arabic. "I know this because I'm Muslim. I hear this and I only cry."
Huseyin Bayri, a witness of the shooting, said he heard the attacker screaming out that he will kill "foreigners."
"I heard a scream at first: 'You shitty [bleep] foreigners. I am German. You will get it.'"
The gunman moved across the street to the mall, which is adjacent to the site of the 1972 Olympics. Located in a middle-class neighborhood in northern Munich, the shopping mall is the city's biggest and a popular destination for shoppers on Friday nights, German lawmaker Charles Huber told CNN.
Lynn Stein, who said she works at the Jack Wolfskin store in the mall, said she heard several shots.
"People were very confused, and they were running and they were screaming," she said. She saw someone lying on the floor of a store who appeared to be either dead or injured. "There's a woman over them, crying."
Profane exchange with a witness
Many citizens posted photos and video of the panic and the shooting on social media. Two videos showed a profanity-filled verbal exchange, between a man on the top level of parking garage and man on a balcony, that ended with gunfire.
The exchange, recorded on two different camera phones, captured an intense conversation that ends in gunfire. The man who appears to be a shooter said insulting things about Turks, did not espouse jihadist ideology and spoke with a German accent.
Police, thinking up to three gunmen might be on the loose, launched a manhunt, putting the city on virtual lockdown.
Police urged residents to stay in their homes. Citizens took to social media to offer help, with one woman tweeting: "Who is stranded in Sendling and shelter needs, PM me and come over"
Shoppers and people on the street stampeded. Thamina Stoll told CNN she was with her grandmother, who lives about three minutes away from the mall, and saw crowds sprinting down the sidewalk.
"There were like 50 people running towards our house to seek shelter, and there was a helicopter circling above us for about 20 minutes and sirens," she said. "And there's still people walking on the streets. They're confused, and nobody knows what's really going on."
At 8:30 p.m., police found a man who took his own life and decided he was the lone gunman, Andrae said.
The investigation will not yield quick answers, he said.
"We have to investigate everything via third person as we cannot question the perpetrator now," he said.
Merkel meeting with security officials
Germany increased security throughout the nation.
Enhanced police patrols were deployed to the Austria-German border, a spokesperson for the Austrian Ministry of Interior told CNN. Special forces from Bavaria and surrounding federal states were brought in to Munich as reinforcements during the search.
Chancellor Angela Merkel called a security council meeting for Saturday. German Federal President Joachim Gauck was "dismayed and shocked" by the shooting, his office said in a statement.
Foreign leaders expressed sympathy for the victims.
Iran's Foreign Ministry spokesman expressed sympathies for Germany, as the state news agency, IRNA reported that the suspected shooter was Iranian-German.
"There is no other way to combat terrorism except through widespread and relentless anti-terrorism campaign," said the ministry spokesman Bahram Qasemi, according to IRNA.
President Barack Obama condemned the attack, as did U.S. Secretary of State John Kerry. In a statement, Kerry said, "We are in close contact with German officials and stand ready to provide any and all assistance requested by our close friend and ally Germany in this time of crisis."
The U.S. military began a count of all its personnel -- some 62,000 -- and their dependents throughout Europe to confirm their safety.