President Barack Obama's national security adviser urged Ugandan President Yoweri Museveni on Sunday not to sign an anti-gay law, saying it would be a "huge step backward" for Uganda and the world.

Susan Rice said she had spoken by phone to Museveni on Saturday night after he told members of his party that he would sign the law, which imposes harsh sentences for those convicted of homosexual acts.

Museveni last month had indicated he was planning to shelve the bill, which has attracted fierce criticism from Western donors and human rights groups since its inception in 2009.

"People everywhere deserve freedom, justice, and equality. No one should be discriminated against for who they are or whom they love," Rice said via Twitter.

Rice said she was saddened that the decision "will put many at risk and stain Uganda's reputation." She said she told Museveni the law is a "huge step backward for Uganda and the world."

(Reporting By Steve Holland; Editing by Jonathan Oatis)