A tough ban on same-sex relationships that threatens violators with 14-year prison terms has been quietly signed into law by the president of Nigeria, Africa’s most populous nation, a step that rights advocates have long feared not only as a repression aimed at gays but as an affront to basic freedoms of speech and assembly.

The ban, known as the Same Sex Marriage Prohibition Act, was passed by Parliament in May but was not signed by the president, Goodluck Jonathan, until Jan. 7, Nigerian news agencies reported Monday from Abuja, the capital.

It is considered the most significant setback to gay rights in Africa, where same-sex relationships are already widely prohibited. The law took effect as gay-rights advocacy is gaining traction elsewhere, led by the United States and other Western nations where the legality and acceptance of same-sex marriage and civil unions are expanding.

Under the Nigerian law, it is illegal not only to engage in an intimate relationship with a member of the same sex, but to attend or organize a meeting of gays, or patronize or operate any type of gay organization, including private clubs. Any same-sex marriages or partnerships accepted as legal in other countries would be void in Nigeria.