Taiwan's parliament legalises same-sex marriage in a landmark first for Asia as the government survives a last-minute attempt by conservatives to pass a watered-down version.