NAIROBI, Kenya — Kenya’s High Court on Friday upheld laws that criminalize gay sex, declining to join the handful of nations that have recently abolished a prohibition imposed by Britain during the colonial era.

The unanimous ruling by a three-judge panel of the court, announced in a courtroom packed with activists who wanted to see the laws overturned, keeps Kenya aligned with most of Africa. Anti-gay laws and conservative cultural mores remain prevalent across most of the continent. In addition to the threat of prosecution, discrimination and violence against lesbian, gay, bisexual and transgender people are common.

“A sad day for the rule of law and human rights,” said Eric Gitari, a co-founder of the National Gay and Lesbian Human Rights Commission, a Kenyan civil rights group, who was one of the petitioners in the case. He said he and others would appeal the ruling.

Téa Braun, director of the Human Dignity Trust, an international gay rights advocacy group, noted in a statement that Kenya’s constitution guarantees human dignity and freedom from discrimination.