The High Court rejected sections of Botswana's penal code punishing gay sex with up to seven years in prison, deeming it unconstitutional.
The ruling stated that penalizing people for who they are is both disrespectful and discriminatory, and said that the law shouldn't deal with private acts between consenting adults.
The judges of the High Court said sexual orientation is innate and not a "fashion statement," and cited a comment from President Mokgweetsi Masisi — which was shared by LEGABIBO, or Lesbians, Gays and Bisexuals of Botswana, ahead of the decision — in their ruling.
"There are also many people of same-sex relationships in this country who have been violated and have also suffered in silence for fear of being discriminated," Masisi said. "Just like other citizens, they deserve to have their rights protected."
In recent years, Botswana has taken other steps toward protecting LGBTQ rights. The High Court in 2017 ruled that the government should issue a transgender man documentation reflecting his identity, and in 2016 an appeals court ruled that LEGABIBO could register as a nonprofit.
Tuesday's ruling came less than a month after Kenya's High Court upheld similar sections of its own penal code in a unanimous ruling that disappointed the country's vibrant gay community. The laws prescribe up to 14 years in prison for people convicted of homosexual acts.
More than two dozen countries in sub-Saharan Africa have laws criminalizing gay sex, often holdovers from colonial times. Earlier this year, the southern African nation of Angola decriminalized same-sex activity and banned discrimination based on sexual orientation.
The Associated Press contributed to this report.