Parliament has passed the Births, Deaths, Marriages and Relationships Registration Bill, which allows people to change their birth certificates to reflect who they are.
The bill changes the process for amending the sex shown on a birth certificate from one which requires people to go through the Family Court - including appearing before a judge and disclosing private medical information - to a simple self-selecting administrative process.
The bill represents a victory for trans, non-binary, intersex and takatāpui people and is similar to laws in about 15 other countries.
In particular, it will not require people to provide evidence of medical treatment, which can be difficult to access, intrusive, and which the person in question may not want.
Green MP Dr Elizabeth Kerekere cried in the house as she spoke in support.
"This bill recognises that those who need to amend their birth certificate can do so, that the courts do not have the right to make that choice for them, that parents do not have that right, that cis-gender people who don't even know them or care about them do not have that right.
"As a takatāpui, cis-lesbian fem ally to our takatāpui, trans and intersex non-binary whānau, I am very proud to commend this bill to the house," she said.
"It is with great pleasure that after generations of systemic discrimination, decades of community activism and many years of work in this house that we are passing this amendment."
Initially the bill - first introduced in 2017 - was intended to be a simple one focused on access to digital information and a review of burial and cremation, but after the first reading those in the select committee were urged to include the birth certificate change to align with an earlier petition lodged by Allyson Hamblett, calling for such changes.
The committee agreed to the idea of adding in the change, but that required a Supplementary Order Paper (SOP) to amend the original bill.
As a result, the bill was put on hold in 2019 so the amendment could be reviewed and subject to public feedback at another select committee, which was part of why it took so long.
The consultation hearings had been marred by transphobic submissions, and had been "something else".
"We would have hoped that all submitters presented with accurate information and a genuine care for the humanity of all New Zealanders, sadly that was not the case.
"We acknowledge that many members of takatāpui, trans, intersex and non-binary communities and your allies were infuriated and traumatised by the gaslighting, transphobia, and particularly transphobic misogyny that was expressed in those hearings."
"This bill upholds the mana, the wairua, the mauri of our takatāpui, trans, intersex and non-binary whānau. It will be the first of many."
Internal Affairs Minister Jan Tinetti, who tabled the amendment to the Bill, said it was a proud day in Aotearoa's history.
"Parliament has voted in favour of inclusivity and against discrimination," she said.
"I would like to acknowledge that there will be disappointment from overseas-born New Zealanders as they will not be able to access self-identification at present. This is because the changes only apply to New Zealand birth certificates at this stage.
"Work will be done to address this, starting with further consultation with those affected. This will only further strengthen the milestone we have achieved today," Jan Tinetti said.
During her own speech, Tinetti said while it was a small change in legislation it was a big change for many in the community.
"Today is a day about inclusion, having the right to have a birth certificate that reflects who you know yourself to be."
She also challenged the discriminatory nature of some of the reaction to the bill.
"Throughout this journey of this bill there have been real people who have been hurt when they have been belittled, mocked and discriminated against. People who like any one of us just want to be accepted for who they are and be treated with dignity and respect.
"A lot of the discussion has been aimed at our trans women, who - as a cis-gendered woman - I am proud to stand alongside and call my sisters ... trans misogyny is still misogyny so I stand strong in challenging this discrimination."
The self-identification provisions are set to come into force in 18 months.