Activists celebrate outside the High Court in Gaborone, Botswana, June 11, 2019. Botswana became the latest country to decriminalize gay sex when the High Court rejected as unconstitutional sections of the penal code that punish same-sex relations with up to seven years in prison. AP

Johannesburg -- Botswana became the latest country to decriminalize gay sex on Tuesday in a landmark case for Africa. The High Court of Botswana rejected as unconstitutional sections of the penal code punishing same-sex relations with up to seven years in prison.

Jubilant activists in the packed courtroom cheered the unanimous decision in the southern African nation that is seen as one of the continent's most stable and democratic. The ruling came less than a month after Kenya's High Court upheld similar sections of its own penal code in another closely watched case that left LGBT rights advocates disappointed.

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.

Get Breaking News Delivered to Your Inbox

According to the International Lesbian, Gay, Bisexual, Trans and Intersex Association's 2019 roundup, consensual same-sex sex acts are still officially or unofficially criminalized in 70 U.N. member nations. The same report said the death penalty could still be implemented for consensual same-sex sexual acts in at least 10 nations around the world.

Those arguing against the laws say they leave people in the LGBT community vulnerable to discrimination and abuse while making it difficult to access basic health and other services.

The Botswana-based non-governmental group LEGABIBO, which supported the anonymous petitioner in the case, has said such laws "infringe on basic human dignity."

People in the courtroom were ecstatic, leaping up, clapping and ululating, LEGABIBO legal policy director Caine Youngman told The Associated Press. When the judges said the right to privacy includes the right to choose a partner, "it hit home," he said.

"I'm a gay man. I've been out for many years. Now I can live with my partner without worry," Youngman said. He said the state might appeal "to appease the homophobes" and has 30 working days to do so.

The ruling led to rejoicing from rights groups that had expressed frustration with the Kenyan decision last month, including ones in countries such as Nigeria, Uganda and Ghana where gay sex remains illegal. Amnesty International called on other African nations to follow Botswana's example in "an exciting new era of acceptance."

Botswana's High Court said in its ruling that penalizing people for who they are is disrespectful and discriminatory, and that the law should not deal with private acts between consenting adults.

Sexual orientation is innate and not a "fashion statement," the judges said. "Any criminalization of love or finding fulfillment in love dilutes compassion and tolerance."

The ruling cited the recent decriminalization in India and elsewhere. It also pointed out that all three arms of Botswana's government have expressed the need to protect the rights of the gay community.

Before the ruling, LEGABIBO shared a comment attributed to President Mokgweetsi Masisi: "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. Just like other citizens, they deserve to have their rights protected."

The judges cited the president's comment in their ruling.

Botswana in recent years has taken other steps toward protecting LGBT 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.

"It is a day to celebrate pride, compassion and love," UNAIDS executive director Gunilla Carlsson said in a statement after Tuesday's ruling. Prohibitive legal environments increase the vulnerability of gay men, transgender women and others to HIV, the statement said.