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….story continues below…