Mauritius' highest court has decriminalised gay sex, saying the ban reflected colonial-era, rather than indigenous values.
British colonialists first criminalised "sodomy" in 1898, but the law has not been enforced in recent years.
The gay man who brought the case said he was "now free to love whoever I want to without fear".
The ruling comes at a time of rising homophobia and tougher anti-gay laws in some African states.
Most notably, Uganda's President Yoweri Museveni signed a controversial Anti-Homosexuality law in May that imposed the death penalty for "aggravated homosexuality", which refers to sex with children or rape.
Many people in Uganda and other African states argue that homosexuality is "un-African", and contradicts their religious beliefs.
The case in Mauritius was brought by Abdool Ridwan Firaas Ah Seek, who argued that the "offence of sodomy" breached his basic rights, including the right to liberty.
The Supreme Court said the law did not "reflect any indigenous Mauritian values but was inherited as part of our colonial history from Britain".
It "was not the expression of domestic democratic will, but was of course imposed on Mauritius and other colonies by British rule", the judges added.
The ruling means that people can no longer be arrested for having gay sex, but parliament will have to repeal the law to make it legal.
In court papers, the state had argued that it was not "insensitive" to the concerns of the LGBT community, but the criminal code could be changed by parliament only when "favourable" conditions emerged in society.
Mauritius gained its independence in 1968, but kept the ban on gay sex.
Religious groups have strongly opposed moves to repeal it.
Abdool Ridwan Firaas Ah Seek said the ruling would help future generations in Mauritius to "fully and freely embrace their sexuality without fear of being arrested".
The Human Dignity Trust (HDT) said it "finally topples" more than a century of "state-sanctioned stigma against LGBT people in Mauritius".
It added that the ruling sent a message to African countries that still criminalised same-sex relations to abolish their laws.
The law in Mauritius imposes a prison sentence of up to five years for gay sex, but "appears to be largely obsolete in practice", the HDT said on its website.
There are 64 countries worldwide that have laws that criminalise homosexuality, and nearly half of these are in Africa.