Mozambique has decriminalised homosexuality in its new penal code, making it one of a few African countries where same-sex relationships are legal.
The revised code, in force from Wednesday, drops a colonial-era clause outlawing “vices against nature”.
There were no prosecutions under that clause but rights activists have said this change is a symbolic victory.
It comes as other African countries have moved to tighten anti-gay laws.
In Nigeria, a law that came into force last year banned same-sex public displays of affection and introduced a possible 14-year prison sentence for gay sex.
A study released on Tuesday found that 87% of Nigerians supported a ban on same-sex relations.
In Uganda, the government has pledged to introduce a new restrictive law after the last law which criminalised homosexuality was successfully challenged in the constitutional court.
Mozambican rights activists say that the changes in their country could have an impact elsewhere on the continent.
“I am sure that African countries will look at their old laws and see that this is an important step to guarantee that society is free and equal,” Danilo Da Silva, head of the Mozambican gay rights group Lambda, told the BBC.
Historically Mozambique has seen little violence towards gay and lesbian people, BBC Mozambique analyst Zenaida Machado says.
But, she adds, same-sex relationships are still a divisive subject in a country where most people are either religious Christians or Muslims.
While people may be relaxed about homosexuality, many see promoting gay rights as an attack on cultural and religious practices, she says.