The court sentenced Abdalle Ahmed Mumin to two months in prison - but in a surprise move, he was released shortly after the ruling, having already spent around five months in jail.
"When I was taken to Mogadishu central prison, officers refused to jail me granting my immediate freedom," he said on Twitter.
"I went straight to my office to conduct my daily routine. I will continue to be on the forefront of defending press freedom and human rights in Somalia," he added.
Mumin is the secretary general of the Somali Journalists Syndicate (SJS), which had vowed to appeal the ruling, calling it "a pure travesty of justice".
In a text message sent to AFP, SJS president Mohamed Ibrahim said: "This afternoon Abdalle has been released by the prison chief, saying that he has already served this sentence despite the verdict."
Ahead of Mumin's sentencing, rights groups including Amnesty International, Human Rights Watch and the International Press Institute had called for the charges to be dropped, saying Mumin faced ongoing threats and persecution by Somali authorities for advocating the right to freedom of expression.
"Continuing his prosecution not only casts a chilling effect on media freedom and journalism, but it also significantly contributes to the closing civic space in the country," they said in a joint letter to Somalia's attorney general in December.
The SJS and four other media advocacy groups had protested the government's security directive, warning it clamped down on free speech.
Media watchdog Reporters Without Borders, known by its French acronym RSF, ranks Somalia 140th out of 180 countries on its global list of press freedom, with more than 50 journalists killed in the country since 2010.
The nation of 17 million people is the most dangerous country for journalists in Africa, according to RSF.
UPDATED WITH RELEASE OF JOURNALIST: A Somali journalist said he had been freed from jail Monday just hours after a court handed down a two-month sentence on security charges, a case widely criticiZed by rights campaigners and media advocacy groups.
NAIROBI —