JUBILANT CHEERS erupted from tens of thousands of demonstrators packed in rainy streets surrounding Taiwan’s parliament, the Legislative Yuan, followed by more than a few tearful hugs. The news had just arrived that the lawmakers inside had voted to legalise gay marriage. Taiwan is the first country in Asia to do so, unless you count Australia and New Zealand.

Lawmakers had been rushing to finalise the bill ahead of a deadline imposed by the constitutional court, the Council of Grand Justices. In 2017, the council ruled that barring same-sex couples from marrying violated their constitutional right to be treated equally and ordered the government to adopt legislation permitting same-sex marriage within two years. The deadline was May 24th; the new law was approved on May 17th.

Not all were convinced that the Legislative Yuan would meet the deadline. To put pressure on lawmakers, crowds of gay-rights activists and their supporters converged on the legislature as three bills on the subject were being debated. They waved rainbow placards that read, “The vote must pass. No concessions in negotiations” and “Not one country, two marriage systems”.

In Asia, Taiwan has long stood out as a bastion of gay rights. The annual gay pride parade in Taipei, the capital, draws tens of thousands, many from overseas. In contrast, sex between men is punishable by death in Afghanistan. Brunei this year also put into effect a criminal code that prescribes execution by stoning for gay sex (although the country’s sultan says it will not be implemented). Gay sex only became legal in India in September, thanks to a court ruling. In mainland China, same-sex marriage is illegal and gay people are often regarded as deviants.

Despite having dragged her feet about implementing the court ruling, Tsai Ing-wen, the president, pointed to the new law as proof of the strength of Taiwan’s democracy. “Today is a proud day for Taiwan,” she declared. “We have let the world see our values of goodness and tolerance in our land.”

Before she took office in 2016, Ms Tsai had declared herself a supporter of same-sex marriage. “In the face of love, everyone is equal,” she simpered. But in the face of a backlash from opponents of gay marriage, including Christian groups, she crumbled. On the defensive after adopting a controversial pension reform, and fearful of a pummelling in municipal elections in 2018, she dropped gay marriage. Her Democratic Progressive Party (DPP) was pummelled anyway. In the end, the courts took the decision out of Ms Tsai’s hands. But she still hesitated to fulfil the supreme court’s ruling, in part because the results of referendums held at the same time as the municipal elections implied that voters were not enthusiastic.

Opponents of gay marriage came up with two of the three bills that lawmakers debated this week. They would have accorded second-class status to gay marriage—in fact, they did not even use the word “marriage”, speaking instead about “same-sex unions” and “same-sex family relationships”. But Ms Tsai used the DPP’s majority to push through the most progressive bill.

Even this bill does not give gay couples exactly the same rights as heterosexual ones. It does not allow gay couples to adopt children to whom they are not related. Nor does it permit marriages with foreigners, unless they come from countries that have also legalised gay marriage. And it contains a woolly clause that implies that gay marriages will not create legal ties with in-laws. That may create problems for same-sex spouses who want to adopt their partner’s surname, for example, or argue that they should not be obliged to testify against their partner’s relatives in court.

Despite these sops, conservatives are still angry. Sammy Yu, an opponent of gay marriage, points out that voters approved a referendum demanding that the civil code restrict the definition of marriage to a union involving a man and a woman. He says the new law is “really damaging to democracy”. But ignoring the supreme court would have been damaging too, and would not have achieved anything. It had ruled that, if parliament did not act, gay couples should be allowed to register their marriages with local authorities from May 24th anyway. By May 7th more than 250 gay couples had applied, according to the Ministry of Interior. Ms Tsai, meanwhile, has fallen back on platitudes. “We need to learn about understanding and coexistence,” she avers.