Taiwan has become the first country in Asia to legalise same-sex marriage, as its parliament shot down last-minute objections from conservative politicians to approve the change in a vote on Friday.
The constitutional court had given parliament two years to come up with legislation on same-sex marriage, after ruling that gay couples had the right to legally marry.
But matters were complicated by a referendum in November in which voters convincingly rejected defining marriage as anything other than a union between a man and a woman.
Three possible bills were debated, including two by conservative groups that referred to same-sex "civil-unions" or "family relationships" rather than marriage. These were rejected, and the most progressive of the three was passed.
The successful bill includes limited adoption rights for same-sex couples. It was tabled by the government and begrudgingly backed by gay rights campaigners, who see it as falling short of full equality but at least a step in the right direction.
Thousands of gay rights supporters fathered outside parliament in Taipei on Friday during the debate, awaiting the landmark vote.
President Tsai Ing-wen - whose party holds the majority in parliament - recognised the issue had been divisive but said in a Facebook post that the government's bill was the only option to respect both the court ruling and the referendum.
She wrote on Twitter on Friday morning: "Today, we have a chance to make history and show the world that progressive values can take root in an East Asian society."