In the latest setback for gay people across Africa, Ugandan President Yoweri ­Museveni signed a law Monday that imposes tough penalties for homosexual acts, a move that drew condemnation from around the world and that could jeopardize Uganda’s relationship with the Obama administration and Western donors.

Homosexuality was already ­illegal in Uganda, but the new legislation threatens to usher in an era of harsh treatment of offenders and could lead to widespread oppression of gay men and lesbians, human rights activists say. The legislation imposes a 14-year prison sentence for first-time offenders and life sentences for repeat offenders found guilty of “aggravated homosexuality.”

“1.54 pm: Officially illegal — President Museveni signs law to send me to jail,” Frank Mugisha, a prominent Ugandan gay rights activist, wrote in a tweet.

The law also makes it a crime to fail to report anyone who breaks the law, essentially ensuring that gays will need to live secret lives. The law even makes illegal the “promotion” and “recognition” of homosexual relations, including by any government entity or nongovernmental organization inside or outside Uganda. And for the first time, the law targets lesbians.

The law was signed a week after President Obama described the legislation as morally wrong and said that it “will be a step backward for all Ugandans.” Enacting it, he added, “will complicate our valued relationship with Uganda.”

Global gay rights

Secretary of State John F. Kerry, in unusually strong language aimed at a key African ally, said Monday that the United States was “deeply disappointed” with the law’s enactment and called for its repeal.

“Today’s signing threatens a dangerous slide backward in Uganda’s commitment to protecting the human rights of its people and a serious threat to the LGBT community in Uganda,” Kerry said in a statement. He also expressed concern at the law’s potential “to set back public health efforts in Uganda, including those to address HIV/AIDS, which must be conducted in a non-discriminatory manner in order to be effective.”

Over the past few years, the persecution of gays has escalated across Africa. Same-sex relationships are widely prohibited in the continent’s conservative societies, and politicians and fundamentalist preachers have increasingly targeted homosexuals. From Senegal to Zimbabwe, gays have been detained, attacked by police, tortured and even killed. They have been denied access to health care. In some nations, their graves have been desecrated. In others, gays have faced expulsion.

Uganda’s legislation comes six weeks after Nigerian President Goodluck Jonathan signed into law a ban on homosexuality that imposes 14-year prison terms for anyone entering a same-sex union. It also sets 10-year prison sentences for those who run gay clubs or organizations. The legislation triggered an outbreak of anti-gay attacks in parts of Nigeria.

The Ugandan law is considered to be more repressive than Nigeria’s.

“This deeply offensive piece of legislation is an affront to the human rights of all Ugandans and should never have got this far,” Michelle Kagari, Africa deputy director at Amnesty International, said in a statement. She described the law as “draconian and damaging.”

Kagari added: “This legislation will institutionalize hatred and discrimination against lesbian, gay, bisexual, transgender and intersex people in Uganda. Its passage into law signals a very grave episode in the nation’s history.”

The White House released a statement Monday in which it called the law “abhorrent.”

“As President Obama has said, this law is more than an affront and a danger to the gay community in Uganda, it reflects poorly on the country’s commitment to protecting the human rights of its people and will undermine public health, including efforts to fight HIV/AIDS,” press secretary Jay Carney said in the e-mailed statement. “We will continue to urge the Ugandan government to repeal this abhorrent law and to advocate for the protection of the universal human rights of LGBT persons in Uganda and around the world.”

Other Western nations, including Britain, Belgium, Denmark and Sweden, also condemned the law, with some saying they will reconsider their aid to Ugandan government programs as a result.

In many countries, such as Uganda and Nigeria, homosexuality has been criminalized since British colonial rule, but the laws were seldom enforced. The rapid spread of evangelical forms of Christianity and Islam, both preaching a conservative vision of the family, has convinced many Africans that homosexuality should be eradicated. Today, 38 of Africa’s 54 countries have banned same-sex relationships, according to Amnesty International.

The United States is Uganda’s largest donor, giving more than $400 million in aid annually. Kerry said the administration will conduct “an internal review of our relationship” with the Ugandan government “to ensure that all dimensions of our engagement, including assistance programs, uphold our anti-discrimination policies and principles and reflect our values.”

However, Museveni showed no signs of concern Monday over the law’s potential impact on Western donors, particularly his staunchest Western ally, the United States.

Ugandan officials broke out in loud applause when Museveni signed the bill into law at his official residence in front of journalists and dignitaries. In his address, published in the Daily Monitor, a Ugandan newspaper, he accused unnamed “arrogant and careless Western groups” of seeking to recruit young Ugandan children into homosexuality.

“There’s now an attempt at social imperialism, to impose social values. We’re sorry to see that you [the West] live the way you live, but we keep quiet about it,” he said, according to the Reuters news agency.

Discussing Western pressure not to sign the bill, Museveni said: “We Africans always keep our opinions to ourselves and never seek to impose our point of view on others. If only they could let us alone.”

Museveni’s defiance comes as he faces a presidential election in 2016 and growing populist criticism for seeking to remain in power for life. In Uganda, the new law will no doubt increase his popularity. In a 2009 Pew Research Center survey, roughly eight in 10 Ugandans described homosexual behavior as “morally wrong.”

The anti-gay bill, introduced in 2009, initially sought the death penalty for homosexual acts, but that proposal was removed after an international outcry. Shortly after Obama’s denouncement, Museveni indicated that he would not sign the bill, to give scientists a chance to prove that homosexuality was genetic in nature rather than a choice by individuals. In his address, Museveni said he was convinced that it was a lifestyle choice and hence needed to be discouraged by society.

Activists are concerned that the law could have ripple effects in many areas of the continent, leading other governments to pass similar anti-gay legislation.

Activists in Uganda vowed Monday to challenge the law.

Museveni “knows we shall overturn this law in the constitutional court & with our determination we won’t stop at nothing,” Mugisha wrote in another tweet.