"We have identified the man as Martin Adler, a photographer and Swedish citizen," foreign ministry spokeswoman Nina Ersman said.
Adler worked for, among others, Swedish tabloid Aftonbladet, both as a writer and a photographer, the paper confirmed.
"He was down there for us and he was going to file reports," Thomas Sundgren, an Aftonbladet editor, told AFP. "He was also a prized photographer.
"We are very, very shocked of course," he said.
Adler was based in Västerås, west of the Swedish capital, Ersman said.
He was born in Stockholm of Anglo-Swedish parents.
As a freelance cameraman, he worked in dozens of war zones including El Salvador, Rwanda, Chechnya, Afghanistan, Eritrea and Iraq.
He won several prizes, including an Amnesty International Media Award for a story on the kidnapping and sale of women in China.
In 2004, he won the Rory Peck Award for Hard News for his account of the US army's operations in Samarra, Iraq.
Tina Carr, director of the Rory Peck Trust in London, said: "Martin Adler's death in Somalia is a terrible tragedy. He was killed doing what he had always done: filming the truth. He was a true brave freelancer whose pictures and stories shed light on some of the most dangerous situations in the world. This is an awful loss, but most of all to his wife and family who are very much in our thoughts."
According to witnesses, Adler was shot Friday in the Somali capital while attending a mass demonstration organized by the Islamic courts union that seized Mogadishu this month.
An unknown gunman shot him in the chest at close range at a rally site in the southern part of the city where some 4,000 Islamists were demonstrating in support of the courts, the witnesses said.
"He was shot and killed while attending the rally," said Mohamed Amin, a Somali journalist who was at the scene.
"He died on the spot," Amin told AFP.
A second witness said a gunman had shot the journalist in the chest, near his heart in deliberate fashion and that the surrounding crowd had scattered in panic.
"It was not an accident," the witness told AFP, speaking on condition of anonymity citing security fears. "It was an intentional murder by someone who wanted to kill a journalist."
A speaker at the rally condemned the killing and pledged that the gunman or gunmen would be punished.
"He is not one of us," the speaker, a cleric, told the crowd. "We are against the killing of a journalist who is a guest.
"This person deserves to be punished for killing somebody for no reason," the speaker said. "With the help of Allah we will find him and punish him accordingly."
Several witnesses said the shooting may have been linked the publication by a Danish newspaper last year of cartoons of the Prophet Mohammed that enraged many in the Muslim world, including Somalia.
Mogadishu has been under the control of militia loyal to the city's Islamic courts since June 5 when they seized most of the capital, ousting a US-backed warlord alliance.
The situation has been tense with anti-US sentiment running high since. Demonstrators at Friday's rally burned the flags of the United States and Ethiopia, which the courts have accused of sending troops to back the warlords.
The killing is the first of a foreign journalist in the city since the shooting death last year of BBC producer Kate Peyton, who was slain outside a hotel in Mogadishu on February 9, 2005.
It underscores insecurity in the capital that has kept the country's largely powerless transitional government from setting up shop there.
The government, which on Thursday signed a mutual recognition and peace agreement with the Islamic courts, is based in the town of Baidoa, northwest of Mogadishu.