Uganda's president has signed a controversial anti-gay bill that allows harsh penalties for "homosexual offences", calling them "mercenaries" and "prostitutes".

Yoweri Museveni on Monday signed the bill, which holds that homosexuals be jailed for long terms, outlaws the promotion of homosexuality and requires people to denounce gays.

He denounced gays and spoke in lurid detail about sexual activity while signing one of the world's toughest anti-gay laws, which has come under fierce criticism from the US president, Barack Obama, who has warned that ties between Kampala and Washington would be damaged.

"Homosexuals are actually mercenaries. They are heterosexual people but because of money they say they are homosexuals. These are prostitutes because of money," Musaveni said.

He added "there is something really wrong with you" if you were gay, adding that he didn't understand how a man could "fail to be attracted to all these beautiful women and be attracted to a man".

In an interview with Al Jazeera, Uganda's minister for ethics and integrity, Simon Lokodo, said that homosexuality was "contrary to the order of nature and therefore it is illegal".

He said he could teach gay people to be straight, and had done so.

The US Secretary of State, John Kerry, said his country was reviewing its relationship with Uganda now that the bill has been enacted.

Earlier in the day, Ugandan government spokesman Ofwono Opondo said, the president "wants to sign it with the full witness of the international media to demonstrate Uganda's independence in the face of Western pressure and provocation."

The bill is popular in Uganda, but rights groups have condemned it as draconian in a country where homosexuality is already illegal.

"Outsiders cannot dictate to us, this is our country," said Museveni. "I advise friends from the West not to make this an issue, because if they make it an issue the more they will lose."

'Aggravated homosexuality'

Navi Pillay, the UN high commissioner for human rights warned the law was "formulated so broadly that it may lead to abuse of power and accusations against anyone".

The Netherlands froze a $9.6m subsidy to Uganda's legal system, arguing that "if the judiciary is to enforce such laws, we do not wish to assist that process".

Denmark and Norway said they would redirect around $8.5m each in government aid towards private sector initiatives, aid agencies and rights organisations.

Museveni's decision to sign the bill comes less than a week since he announced plans to put the bill on hold to give scientists a chance to prove that homosexuality could be triggered by genes and is not a "lifestyle choice".

The law punishes first-time offenders with 14 years in jail. It also sets life imprisonment as the penalty for acts of "aggravated homosexuality".

The bill originally proposed the death penalty for some homosexual acts, but that was later removed amid international criticism.

Widespread homophobia

Homophobia is widespread in Uganda, where American-style evangelical Christianity is on the rise.

Gay men and women in Uganda face frequent harassment and threats of violence, and rights activists have reported cases of lesbians being subjected to "corrective" rapes.

In 2011, prominent Ugandan gay rights campaigner David Kato was bludgeoned to death at his home after a newspaper splashed photos, names and addresses of gays in Uganda on its front page along with a yellow banner reading "Hang Them".

Uganda is a key Western ally in the fight against armed groups in Somalia where Ugandan troops have formed the backbone of the African Union peacekeeping force battling al Qaeda-linked fighters.