A Moroccan court on Tuesday handed a four-month suspended sentence and a $50 fine to Moroccan journalist and rights activist Omar Radi on charges of insulting a judge on Twitter, in a case that outraged advocates of free speech in the country.

Radi, 33, tweeted last April that the judge was working under orders when he gave heavy sentences to leaders of protests that took place in northern Morocco in late 2016 and early 2017 over the country's social and economic woes.

"I was expecting to be acquitted as I am not guilty and was only expressing my own opinion," Radi told Reuters News Agency after the verdict. He said he will appeal the verdict.

Local rights groups have decried the increasing use of the penal code in trying free speech cases instead of the more lenient publishing code, which has had no provision for imprisonment since a reform in 2016.

"He should never have been put on trial in the first place or sentenced for expressing peaceful views on social media. This sentence reinforces the message that anyone in Morocco who stands up for human rights will be punished," said Amnesty International in a statement.

The prosecutor said Radi's tweet was directed at the judge in person and not the judiciary. Radi and his lawyers denied that.

Radi was released on bail on December 31 after spending five days in prison. His case triggered a wave of solidarity by human rights activists and groups including Morocco's Freedom Now, Human Rights Watch and others which all demanded his immediate release.

Moroccan courts have in recent months sentenced a dozen individuals to prison terms of up to four years on charges that include insulting constitutional institutions or public servants and inciting protests, according to rights activists.