With a 65-34 vote on Wednesday, the bill was shuttled off to Gov. Steve Bullock, who is likely to sign it, his spokeswoman, Judy Beck, told NBC News. Montana's Supreme Court struck down the law in 1997, but a block of Republican lawmakers had stymied efforts to repeal it, the Billings Gazette reported.

“It’s not about encouraging a lifestyle,” Rep. Bryce Bennett, D-Missoula, an openly gay Montana lawmaker, was quoted as saying Tuesday by the newspaper. “It’s simply about respecting privacy between two adults. … It’s just as simple as saying that all Montanans deserve dignity and respect.”

The old law made “deviate sexual conduct,” or sexual relations between people of the same sex, a crime. Those convicted of it faced a prison term of up to ten years and/or a maximum $50,000 fine.

The Supreme Court in 2003 ruled that a Texas state law criminalizing gay sex was unconstitutional, thereby striking down some 14 active anti-sodomy laws on the books in other states and Puerto Rico.

"As a matter of law, sodomy laws, as they apply to same-sex couples and in some states different sex couples, were struck down by the U.S. Supreme Court in our 2003 lawsuit Lawrence v. Texas," Susam Sommer, director of constitutional litigation at Lambda Legal, said in a statement.

Nonetheless, Montana's repeal "goes a long way in building a supportive environment for LGBT people and their families," she added, noting that the ongoing presence elsewhere of "these unconstitutional laws in state penal codes implicitly stigmatizes gay people and puts them and many others at risk of unlawful prosecutions. It is time every state cleans up its books and cleans up its act."

Eleven states still have laws on their books outlawing oral and anal sex between same-sex couples, while another nine have statutes outlawing oral and anal sex for everyone, according to Lambda Legal.

The 2003 Supreme Court case has been cited by pro-gay marriage supporters in arguments before the high court on whether gays and lesbians should be allowed to wed. The court is expected to rule in those cases in June.