Botswana’s high court struck down laws banning gay sex on Tuesday, handing a significant but still comparatively rare victory to sexual minority rights campaigners in Africa.

Declaring that the state could no longer “be a sheriff in people’s bedrooms”, judges in Gabarone, Botswana’s capital, unanimously ruled that legal provisions criminalising same-sex relations were unconstitutional.

“A democratic society is one that embraces tolerance, diversity and open-mindedness,” Justice Michael Leburu told the court, prompting cheers and applause after the ruling was read.

“Human dignity is harmed when minority groups are marginalised. Sexual orientation is not a fashion statement. It is an important attribute of one’s personality.”

The ruling, which will cement Botswana’s reputation as one of Africa’s most democratic and progressive states, strikes out clauses in the penal code that impose a prison sentence of up to seven years for carnal acts “against the order of nature”.

It also amends a law that made acts of gross indecency committed in private punishable by up to two years in jail. No-one had been convicted under either law since at least 2003.