Kenya's High Court has ruled against campaigners seeking to overturn a law banning gay sex.
The three judges rejected claims that the colonial-era law violated the new constitution, which guarantees equality, dignity and privacy.
The penal code criminalises "carnal knowledge against the order of nature" - widely understood to refer to anal intercourse between men.
Gay sex is punishable by up to 14 years in prison.
It is not clear whether there have ever been any convictions for gay sex in Kenya.
But Kenya's National Gay and Lesbian Human Rights Commission (NGLHRC) had pushed for the law to be scrapped, arguing that it gave rise to a climate of homophobia.
The law is specific to men but activists say that lesbian, bi, trans and non-binary voices are also affected.
"The general public doesn't know that the law only applies to male relationships," says Njeri Gateru, a co-founder of the (NGLHRC).
"They include other sexual minorities in their prejudice."
Many African countries still enforce strict laws governing homosexuality, in most cases a legacy of laws imposed by the colonial rulers.
The case was initially filed by LGBT rights activists in 2016. They argued that the state had no business regulating matters of intimacy.
It wasn't heard until February 2018 and the verdict was initially expected in February 2019 - but it was delayed until Friday.
What did the judges say?
The judges dismissed the argument that a ban on gay sex contravened the 2010 constitution, which protects all citizens' privacy and dignity.
Presiding judge Roselyne Aburili declared to a packed courtroom: "We find the impugned sections [of the penal code] are not unconstitutional".
She also argued that allowing gay sex would "open the door for same-sex unions". In her commentary she added that there was "no conclusive scientific proof that LGBTQ people are born that way," she added.
The judges ruled that while they respected changes to laws banning gay sex in other countries, it was the court's duty to respect prevailing Kenyan values.
What has the reaction been?
One of the petitioners, Eric Gitari, has vowed to appeal against the decision which he called "very biased".
Human rights groups also criticised the ruling, with the Kenyan Human Rights Commission going as far as to say that it "legitimises homophobia by upholding a colonial culture of exclusion, discrimination and violence against minorities".
But, it is a divisive issue in Kenya and many welcomed the judges' verdict.
Catholic bishop Alfred Rotish told Reuters news agency outside the court: "We cannot be another Sodom and Gomorrah".
Most Christian and Muslim groups support the current law, and the Kenyan attorney-general had argued against decriminalisation.
What is the gay scene like in Nairobi?
Megha Mohan, BBC Gender and Identity reporter
There are unofficial gay clubs and advertised events in Kenya's cities.
"The LGBT community in Kenya have created an amazing tribe and culture for themselves," says Brian Macharia, an activist for the Gay and Lesbian Coalition of Kenya.
"There is a ballroom scene, a drag scene - vibrant bisexual community, a lesbian scene. Young people are driving the community forward through social media."
Gay men also use dating apps - although visitors with international roaming do get a warning about the legal status when logging in while in Kenya.