Russia's constitutional court has rejected an attempt by rights groups to seek the repeal of a law that bans people from speaking out against Russia's invasion of Ukraine.

In a lengthy ruling, the court rejected the bid to strike down Article 20.3.3 of the code of administrative offences, which bans "public actions aimed at discrediting the use of the armed forces".

Campaigners including legal defence group OVD-Info and the banned human rights organisation Memorial had filed the case in April, saying it violated articles of Russia's constitution including on free speech and freedom of conscience.

One of the plaintiffs was Ilya Yashin, an opposition politician who was three times fined for anti-war statements under Article 20.3.3 and later sentenced to eight and a half years in prison last December on charges of spreading "false information" about the army.

In a lengthy ruling on Yashin's complaint, the Constitutional Court said decisions taken by state bodies to "defend the interests of the Russian Federation and its citizens and support international peace and security" could not be arbitrarily questioned on the basis of subjective opinions.

To do so, it said, would mean to deny "the legal character of the Russian Federation, the supremacy of its constitution and the duty to comply with its prescriptions, which by virtue of the constitution of the Russian Federation is inadmissible."

Violetta Fitsner, a lawyer with OVD-Info, described the ruling as a disgrace.

Another of the complainants, Maria Nemova, said the ruling confirmed that the point of the law was to suppress dissent: "Only people who support the war can speak out, and those who don't agree must remain silent."

Authorities have launched more than 6,500 cases under Article 20.3.3, OVD-Info said, including against people who staged solo anti-war demonstrations, posted their opinions online or wore anti-war symbols on their clothes.

Individuals face an initial fine of up to 50,000 roubles ($595). If they repeat the offence, they can face criminal charges of "discrediting the armed forces", which carries a prison term of up to five years, while spreading "false information" about the army is punishable by up to 15 years.