Forty-seven men went on trial in Nigeria on Wednesday for public displays of affection with members of the same sex, an offence that carries a 10-year jail term in the country.

The men were among 57 arrested in a police raid on a hotel in the impoverished Egbeda district of the commercial capital, Lagos, in 2018. They pleaded innocent at a hearing last month.

Campaigners say the case is an important test of a law banning gay marriage and same-sex “amorous relationships”, which came into force five years ago.

Xeenarh Mohammed, the executive director of the Lagos-based Initiative for Equal Rights (TIERS), said the law had historically been used to harass and blackmail gay people but there had not been any convictions.

“People have been detained, men and women, at different gatherings but no cases had ever gone before a judge. We have to establish that people have a right to meet that shouldn’t be a crime under any law in any country,” said Mohammed.

Homosexuality is illegal in most African countries. In several, gay people face life imprisonment or the death penalty. Some religious groups brand it a corrupting western import.

Police said the Nigerian men were being initiated into a gay club. The accused say they were attending a birthday party.

The Same Sex Marriage Prohibition Act, which banned gay relationships and entrenched intolerance of sexual minorities in Nigerian society, was signed by Goodluck Jonathan, then president, in January 2014.

The law caused an international outcry, with condemnation from global human rights organisation and western governments. Human Rights Watch called it a “sweeping and dangerous piece of legislation”.

“Police officers will stop you and then get you arrested, extort money from you and begin to call you names,” Smart Joel, 25, one of the defendants, said before last month’s hearing. “I just wish the case will be quickly dismissed as soon as possible.”

Defendants have been granted bail of 500,000 naira (£1,048), a significant sum locally.

Two days of hearings have been scheduled this week to allow the prosecution to make its case. The trial is likely to last for several months.

Surveys have historically shown high levels of homophobia in Nigeria, but some have pointed to what campaigners say is a tentative, growing acceptance of gay men and women.

In June, high court judges in Botswana ruled that laws criminalising same-sex relations were 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.

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.

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

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

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.