High court judges in Botswana have ruled that laws criminalising same-sex relations are unconstitutional and should be struck down, in a major victory for gay rights campaigners in Africa.

Jubilant activists in the packed courtroom cheered the unanimous decision, which came a month after a setback in Kenya when a court rejected an attempt to repeal similar colonial-era laws.

“Human dignity is harmed when minority groups are marginalised,” Justice Michael Leburu said as he delivered the judgment. “Sexual orientation is not a fashion statement. It is an important attribute of one’s personality.”

The ruling was welcomed enthusiastically by campaigners across the African continent, where homosexuality is illegal in most countries. In several, gay people face life imprisonment or the death penalty.

History made in Botswana

Human rights for all. pic.twitter.com/Jlv7KisZYq — Keikantse E. Phele (@ke_phele) June 11, 2019

Botswana is regarded as one of Africa’s most stable and democratic nations but homosexuality was outlawed under the country’s penal code of 1965.

“A democratic nation is one that embraces tolerance, diversity, and open-mindedness … societal inclusion is central to ending poverty and fostering shared prosperity … The state cannot be a sheriff in people’s bedrooms,” Leburu said.

In March, the court postponed a ruling on the issue after an unnamed applicant challenged two sections of the penal code under which offenders face a jail sentence of up to seven years.

“This is a historic ruling for lesbian, gay, bisexual and transgender people in Botswana,” said Gunilla Carlsson, executive director of UNAids. “It restores privacy, respect and dignity to the country’s LGBT people, and it is a day to celebrate pride, compassion and love.”

Scenes of joy as decriminalization Of homosexuality made official in Botswana #repeal164 pic.twitter.com/pBch7o6kdh — Ryan Brown (@ryanlenorabrown) June 11, 2019

Activists had hoped that the government would do away with oppressive laws that brand homosexuality as “un-African”. The Botswana-based NGO LeGaBiBo which supported the anonymous petitioner in the case, has said such laws “infringe on basic human dignity”.

When the judges said the right to privacy included the right to choose a partner, “it hit home”, said Caine Youngman, legal policy director at LeGaBiBo. “I’m a gay man. I’ve been out for many years. Now I can live with my partner without worry,” Youngman said.

Thato Game Tsie, an outreach worker, said scrapping the anti-gay laws would help the community access healthcare and treatment more easily. “There are many services we require as gay men that some nurses are not aware of, and if we go to a government hospital there will be those negative comments said to you,” Game Tsie said. “So we just want to be free to access these services.”

Kenyan judges rejected the precedent set last year by India, which legalised gay sex between consenting adults, as well as a series of other judgments across the Commonwealth and elsewhere, and said Kenya should make its own laws to reflect its own culture.

Téa Braun, director of the Human Dignity Trust, an international NGO using the law to campaign for better rights for the LGBT community, said Tuesday’s decision was “a huge win”.

“This judgment, which comes less than three weeks after a deeply regressive decision on the same issue from the Kenya high court, is legally sound, groundbreaking and courageous, and is a ray of hope for all those LGBT Africans looking to their legal systems for justice and fair treatment,” Braun said.

At the Botswana high court hearing in the capital, Gaborone, in March, lawyers for the applicant said public opinion on same-sex relationships had evolved and employment laws now outlaw discrimination on grounds of sexual orientation.

In 2016 the country’s appeals court ruled that the government was wrong to refuse to register an organisation representing homosexuals and other minority sexual groups.

At a meeting on gender-based violence in December, President Mokgweetsi Masisi said many people in same-sex relationships in Botswana “have been violated and have also suffered in silence. Just like other citizens, they deserve to have their rights protected,” he said.

Angola, Mozambique and the Seychelles have scrapped anti-gay laws in recent years.

In Tanzania, authorities in Dar es Salaam, the biggest city, have launched a series of crackdowns on gay people in recent years. In the most recent the city’s governor called on citizens to identify gay people so they could be arrested, forcing hundreds of people into hiding.