Botswana has become the latest country to decriminalise gay sex, a landmark case for Africa, as the country's High Court rejected laws punishing it 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 had upheld similar sections of its own penal code in another closely watched case.
"Botswana is the ninth country in the past five years to have decriminalised consensual same-sex relationships," UN spokesman Stephane Dujarric said.
"Consensual same-sex sexual relationships remain criminalised in at least 67 countries and territories worldwide," he told reporters at UN headquarters in New York.
More than two dozen countries in sub-Saharan Africa have laws criminalising gay sex, often holdovers from colonial times. Earlier this year, the southern African nation of Angola decriminalised same-sex activity and banned discrimination based on sexual orientation.
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 cheering, 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 penalising 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 criminalisation of love or finding fulfillment in love dilutes compassion and tolerance."
The ruling cited the recent decriminalisation 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.
UN Secretary-General Antonio Guterres joined UN human rights chief Michelle Bachelet and the acting executive director of UNAIDS, Gunilla Carlsson, "in warmly welcoming the landmark decision by Botswana's High Court to decriminalise consensual same sex relations," UN spokesman Dujarric said.
"It is a day to celebrate pride, compassion and love," 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.