ABUJA — The mass arrest of more than 40 Nigerian men suspected by police of performing homosexual acts at a party in Lagos could hinder efforts to stem the spread of HIV in the country, a leading gay rights activist said on Monday.

The men were arrested on Saturday afternoon at a private party in a Lagos hotel, where attendees were offered counseling and testing for the virus which causes AIDS, said Bisi Alimi, a Nigerian lesbian, gay, bisexual and transgender (LGBT) activist.

A police spokesman told local media on Sunday that about 40 "suspected homosexuals were arrested," and said they would soon appear in court to face charges. The police and state government for Lagos were not immediately available to comment on the case.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Former Nigerian President Goodluck Jonathan signed a bill in 2014 criminalizing same-sex relationships in Nigeria. It banned gay marriage, same-sex "amorous relationships" and membership of gay rights groups with penalties of up to 14 years in prison.

Related: Effective Treatment Prevents HIV Transmission Among Gay Couples, Study Finds

"These men were trying to save their lives and make their country better by preventing the spread of HIV," Alimi told the Thomson Reuters Foundation by phone from Britain, having moved from Nigeria after facing death threats for coming out as gay.

Nigeria has the highest HIV rate in West and Central Africa — with around one in 30 or 3.5 million people infected with the virus — according to data from the U.N. AIDS programme (UNAIDS).

Yet the anti-gay law has hindered civil society groups which work with LGBT people in Nigeria, and deterred the community from seeking and sticking with HIV prevention, treatment and support services, rights group Human Rights Watch (HRW) says.

"This case is heartbreaking ... so soon after the arrests at the wedding in Zaria," added Alimi, director of the Bisi Alimi Foundation, which promotes social acceptance of LGBT Nigerians.

Fifty-four people went on trial in Zaria in northern Nigeria in May on charges connected to allegations that they were celebrating a gay wedding, which are illegal under the 2014 law. The trial was adjourned, and it is unclear when it will resume.

Follow NBC Out on Twitter, Facebook and Instagram