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.
Analysis: Milton Nkosi, BBC News
Mozambique's move to decriminalise homosexuality looks in step with recent changes elsewhere, such as Ireland and the US.
But Mozambique is also following the likes of neighbouring South Africa, Democratic Republic of Congo, Ivory Coast and others, where it is not a crime to be gay.
It adds to a mixed picture on the continent as the tightening of laws against homosexuality in some countries shows what a contentious subject gay rights is.
For Mozambique itself, this is a breakthrough but a small one.
The country inherited the penal code from the colonial power, Portugal.
But following independence Mozambique never blindly followed the conservative laws of old Europe.
The change then is a small step forward for Africa's lesbian and gay community.
But in many places, whether homosexuality is legal or not, the real question is about ordinary people's attitudes to gay people, which can still be hostile.
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.