Botswana's High Court has ruled in favour of decriminalising homosexuality in a landmark decision for campaigners.
The court overturned a colonial-era law that imposed up to seven years in prison for same-sex relationships, stating they were unconstitutional.
The move contrasts with Kenya's recent ruling against campaigners seeking to overturn laws on gay sex.
"Discrimination has no place in this world. All human beings are born equal. Homosexuality is another form of sexuality that has been suppressed for years," Justice Michael Leburu said. "Human dignity is harmed when minority groups are marginalised."
Three judges came to the decision unanimously.
Judge Leburu labelled laws banning gay sex as "discriminatory" and added: "Sexual orientation is not a fashion statement. It is an important attribute of one's personality."
The law has been in place since 1965 when it was brought in by the colonial British government.
The case was brought to court by a student who argued society had changed and homosexuality was more widely accepted.
Activists welcomed the decision and described it as a significant step for gay rights on the African continent.
Rights group Amnesty International welcomed the decision as "marking an exciting new era of acceptance, which should inspire other African countries to follow suit".
Laws outlawing same sex relations exist in 31 out of 54 African countries, according to the International Lesbian, Gay, Bisexual, Trans and Intersex Association (ILGA).
Gay sex can be punishable by death in northern Nigeria, Sudan, Somalia and Mauritania. Tanzanian laws mean homosexuality can result in a life sentence.
Angola, Mozambique and the Seychelles have all scrapped anti-homosexuality laws in recent years.
On 24 May, Kenya's High Court ruled against overturning a law banning gay sex.
- BBC / Reuters