"I am free," Abdi Hassan Awlae Qeybdiid, the chief of police in Mogadishu, told the media and Somali supporters as he left the Gothenburg courthouse, news agency TT said.
Swedish police arrested Qeybdiid on Monday in the southern city of Lund, where he had attended an international conference, after getting a tip from a Somali refugee who recognized him and accused him of committing war crimes in the southern Somali port town of Kismayo in 1991.
A special prosecutor for international cases on Thursday asked a Gothenburg court to place him in detention, but the court rejected that request due to lack of evidence.
"The prosecution's evidence was based purely on rumours and speculation," Qeybdiid's lawyer Thomas Olsson told TT.
Under Sweden's "universal jurisdiction" law, Swedish courts can try suspects for genocide committed abroad.
Qeybdiid, 57, was a key aide to late warlord Mohamed Farah Aidid, one of Somalia's most powerful warlords, who carved up the country and have left it without an established and functioning central government since 1991.
The conflict in Somalia, where a new government is this year attempting to establish itself and restore order, has claimed thousands of lives. The warlords run factions of heavily armed militias.
Qeybdiid gained notoriety in October 1993 when he helped to lead heavily armed militiamen in battles with US troops attempting to arrest Aidid.
In events depicted in the Hollywood film "Black Hawk Down," the US operation went wrong from the outset and ended with battles in the capital in which hundreds of Somalis and 18 American special forces troops were killed.
Qeybdiid's arrest sparked angry reactions in Somalia, where more than 5,000 people took to the streets on Wednesday to protest his arrest.
Earlier this week the speaker of the transitional Somali parliament Sharif Hassan Sheikh Aden, speaking at a press conference in Stockholm, said there was no clear line between guilty and innocent in the Somali conflict.
"The Somali people, they killed each other from government to government, clan to clan, sub-clan to sub-clan, from family to family, so nobody is actually innocent," said Aden, who was attending the same conference in Sweden as Qeybdiid.