TAIPEI, Taiwan -- Taiwan's Constitutional Court ruled in favor of same-sex marriage on Wednesday, making the island the first place in Asia to recognize gay unions.

The court said the current civil code that does not permit same-sex marriages was a violation of two articles of the constitution of the Republic of China, Taiwan's official name.

It said that authorities must either enact or amend relevant laws within two years, failing which same-sex couples could have their marriages recognized by submitting a document.

Get Breaking News Delivered to Your Inbox

Legislation enforcing the court's ruling is already working its way through the legislature, where both the ruling and major opposition parties support legalization of same-sex marriage. Surveys show a majority of the public is also in favor, as is President Tsai Ing-wen, Taiwan's first female leader.

Gays and lesbians in Taiwan have formed an effective lobby in recent years, with an annual Gay Pride march drawing tens of thousands. While some conservative religious and social groups have mobilized against same-sex marriage, their influence is much less potent than in the United States and many other parts of the world.

"The need, capability, willingness and longing, in both physical and psychological senses, for creating such permanent unions of intimate and exclusive nature are equally essential to homosexuals and heterosexuals, given the importance of the freedom of marriage to the sound development of personality and safeguarding of human dignity," the court said in its ruling.

Two of the court's 15 justices filed dissenting opinions and one recused himself in the case.

Despite the spread of same-sex marriage in a few regions since 2001, gay and lesbian couples had been allowed to marry in only 22 of the world's nearly 200 countries. In Asia, Taiwan is the first government to legalize such unions, while South Africa is the only country in Africa to allow them. More than 70 countries continue to criminalize homosexual activity.

Globally, the pace of civil rights victories has slowed against the background of a steady stream of reports of anti-gay violence and persecution.

Recent weeks have witnessed large-scale detentions of gay men in Nigeria and Bangladesh, and accounts of roundups and torture of scores of gays in Chechnya. In Indonesia, a major police raid on a gay sauna was followed two days later by the public caning of two gay men.