(CNN) -- Botswana's High Court has overturned a colonial-era law criminalizing consensual same-sex relations in a landmark victory for Africa's LGBTQ movements.

The court in the southern African country unanimously ruled on Tuesday that the legislation was discriminatory, unconstitutional and against the public interest.

"A democratic society is one that embraces tolerance, diversity and open-mindedness," Justice Michael Leburu said, noting that discriminatory law not only serves as a detriment to LGBTQ people, but holds back all of society.

"Societal inclusion is central to ending poverty and fostering shared prosperity," he said.

The ruling comes just a month after Kenya's high court upheld its laws criminalizing homosexuality.

Under section 164 of Botswana's Penal Code, "carnal knowledge of any person against the order of nature," was an offense that carried a maximum sentence of seven years imprisonment. Section 167 made "acts of gross indecency" -- whether in public or private -- a punishable offense, with up to two years in prison.

The case was brought to court in March by Letsweletse Motshidiemang, a 21-year-old student at the University of Botswana, who argued that society had changed and that homosexuality was more widely accepted, local media reported.

The packed court erupted in cheers of joy upon hearing the verdict.

Neela Ghoshal, a senior researcher for Human Rights Watch, told CNN that the ruling sets a "powerful precedent on the continent by recognizing that the criminalization of same sex conduct violates privacy rights and is blatantly discriminatory."

"The High Court is right in declaring that sodomy laws belong in a museum or the archives, not in modern life," she said.

Anna Mmolai-Chalmers, coordinator of Legabibo, a prominent LGBTQ rights group in the country, said that the verdict would have a tangible impact on LGBTQ individuals' daily life, saying that it would help with access to health and legal services.

"Before we were struggling. People have been hiding," Mmolai-Chalmers told CNN.

"This judgement can make a massive change for our lives. This is what excites me the most. The judgement means so much... The court has upheld our dignity, our privacy, and our liberty... It means freedom," she added.

Human rights lawyer Keikantse Phele called the judgement "a welcome development," adding that there is still "lots of work that needs to be done in terms of access to all services, spaces and development."

While homophobic attitudes continue to prevail in parts of the country, Botswana's LGBTQ activists and supporters have marked some victories for the movement in recent years. The 2010 Employment Act made it illegal for employers to terminate contracts on the basis of sexual orientation, in 2014 the High Court ruled that the government had to allow Legabibo to register as an organization, and two landmark rulings in October and December 2017 laid the foundation for trans people to more easily change their official gender on identity documents.

Following a brutal attack on a transgender woman last November, Botswana's President Mokgweetsi Masisi signaled his support for LGBTI people, saying "there are many people in same sex relationships in this country who have been violated and have also suffered in silence for fear of being discriminated. (...) Just like other citizens, they deserve to have their rights protected."

Tuesdays' historic ruling is win for LGBTQ activists and supporters in a country -- and region -- where homosexuality remains largely taboo.

Out of 54 African countries, at least 31 of them have enacted laws making it illegal to have gay sex, according to the International Lesbian, Gay, Bisexual, Trans and Intersex Association (ILGA).

In parts of Nigeria and Somalia, and in Sudan, it is punishable by death; in Mauritania the death penalty is a possible punishment. In Tanzania, being convicted of having same-sex relations can result in life sentences.

In January, Angola's parliament adopted a new penal code, for the first time since it gained independence from Portugal in 1975, which paved the way for lawmakers to remove the provision characterizing same-sex relationships as "vices against nature."

Mozambique removed anti-gay laws in 2015, while São Tomé and Cape Verde have also abolished laws criminalizing gay relationships.

Although Kenya struck down the change to the law that criminalizes homosexuality in May -- and remains a deeply conservative and religious society -- its courts has shown some independence in recent years regarding LGBTQ matters.

In 2018, an appeals court in Mombasa ruled that forced anal exams on people who are suspected of same-sex activity are unconstitutional, following the arrest and forced anal exams of two men in 2015. The decision reversed a 2016 court ruling. Later that year, a Kenyan court temporarily lifted a ban on the controversial film "Rafiki," which told the story of a romantic lesbian relationship.

However, attempts to further criminalize homosexuality have been taken in countries including Uganda, South Sudan, Burundi, Liberia, and Nigeria over the last five years, according to an Amnesty International report. In some African countries, conservative leaders continue to spread harmful and false rhetoric, in which they "openly and falsely accuse LGBTI individuals of spreading HIV/AIDS and of 'converting' children to homosexuality," according to the report.

Across the globe, a staggering 70 UN member states -- almost half of which are in Africa -- still criminalize same-sex relations between two consenting adults, according to ILGA's 2019 state sponsored homophobia report.

In 26 of those countries, the penalty varies from 10 years in prison to life.

The-CNN-Wire
™ & © 2019 Cable News Network, Inc., a Time Warner Company. All rights reserved.