The law was overturned on procedural grounds, but not before U.S. Secretary of State John Kerry compared it to anti-Semitic legislation in Nazi German.
African gays who often face persecution in the streets and sometimes prosecution in courts have a simple plea for Pope Francis ahead of his first visit to the continent: bring a message of tolerance even if you will not bless our sexuality.
Francis travels to Kenya and Uganda, where many conservative Christians bristle at the idea of the West forcing its morality on them, especially when it comes to gays and lesbians. He also visits conflict-torn Central African Republic on a tour that starts on Nov. 25.
While Francis has not changed Catholic dogma on homosexuality and has reaffirmed the church's opposition to same-sex marriage, his more inclusive approach has cheered many gay Catholics while annoying conservatives.
"I would like the Pope to at least make people know that being LGBT (lesbian, gay, bisexual, transgender) is not a curse," said Jackson Mukasa, 20, a Ugandan in Kampala who was imprisoned last year on suspicion of committing homosexual acts, before charges were dropped for lack of evidence.
"Being a gay in Uganda is a challenge. You expect mob justice, you expect to be killed, you expect to be arrested," said Mukasa, who also goes by the name Princess Rihanna.
Homosexuality or the act of gay sex is outlawed in most of Africa's 54 states. South Africa is the only African nation that permits gay or lesbian marriage. The Catholic church holds that being gay is not a sin but homosexual acts are.
Uganda, which is about 40 percent Catholic, has been seen as a bastion of anti-gay sentiment since 2013, when it sought to toughen penalties, with some lawmakers pushing for the death penalty or life in prison for some actions involving gay sex.
The law was overturned on procedural grounds, but not before U.S. Secretary of State John Kerry compared it to anti-Semitic legislation in Nazi Germany. Other Western donors were outraged.
Frank Mugisha, director of Sexual Minorities Uganda and one of the country's most outspoken advocates for gay rights, said he hoped the Pope would bring a message that gays and lesbians should be "treated like any other children of God."
"If he starts talking about rights, then Ugandans are going to be very defensive," said Mugisha, a Catholic. "But I would think if the Pope was here and talking about love, compassion and equality for everyone, Ugandans will listen."
A government spokesman, Shaban Bantariza, said: "We hope the Pope's message will not diverge from the core beliefs of Ugandans."
"We don't view homosexuality as a normal lifestyle but also we have chosen not to persecute those who have fallen victim to it," he said.
While gays feel ostracised by the Catholic church's teachings, Africa's evangelical protestant preachers are often among the most strident opponents of homosexuality.
The lightning progress of gay rights in much of America and Europe, where same-sex couples can marry and adopt children, has encouraged gay Africans but hardened attitudes of those who object to the idea on religious grounds.
U.S. President Barack Obama, whose father was Kenyan, likened discrimination against gays to racism, speaking during a visit to Kenya, where about a third of the population is Catholic.
Francis' ascent to the papacy in 2013, replacing the more conservative Pope Benedict, has heartened gay Africans. They welcomed Francis' comment early in his papacy that: "If a person is gay and seeks God and has good will, who am I to judge him?"
Although many Kenyan Christians are deeply conservative, the country has been comparatively tolerant and now hosts about 500 gay refugees from neighbouring Uganda. Kenyan law calls for jailing those involved in homosexual acts but rarely prosecutes.
David Kuria, a well-known Kenyan gay rights activist, did not hesitate when asked about the message he would give to the pope ahead of the visit.
Recalling that his mother, a devout Catholic, was kicked out of her village prayer group because she had raised a gay son, he said he would say that parents of gays should not be victimised or made to "doubt themselves as parents or as Christians".
"I hope the Pope would say, 'Love everyone,' especially those who are still coming to church."