Young people aged 16 and 17 will be allowed to change their legal gender after the Scottish government rejected moves to keep the minimum age at 18.
Some SNP MSPs were among those who argued that 16 is too young to make such a "profound change".
But the government said lowering the age was in keeping with other rights and responsibilities people gain at 16.
It came during a marathon debate on controversial plans to make it easier for trans people to change gender.
The Scottish Parliament was due to discuss and vote on more than 150 proposed amendments to reforms of the Gender Recognition Act on Tuesday ahead of the final vote on Wednesday.
But it had only dealt with about 64 of the amendments by 23:00, with the session finally finishing shortly after midnight when the lights in the Holyrood chamber - which are on a timer - went out.
Parliamentary authorities had earlier decided that it could continue until 02:00 - a prospect several MSPs were unhappy about, and which would have been unprecedented in the parliament's history.
The debate and votes on the remaining amendments are due to resume at about 13:15 on Wednesday. It is not yet clear whether the final vote will have to be delayed.
The Scottish Conservatives have accused the government of attempting to rush the reforms through parliament before Christmas in an attempt to avoid proper scrutiny.
Parliament had earlier been suspended for about half an hour when protestors shouted "shame on you all" and "there is no democracy here" from the public gallery as MSPs voted against a move to make it harder for sex offenders to change gender.
Members of the public were later allowed back into the galleries, with MSPs describing the decision to remove them as "a disproportionate response" to the heckling.
The proposals will remove the requirement for a diagnosis of gender dysphoria.
They will also lower the minimum age for applicants from 18 to 16 and drop the time required for an applicant to live in their acquired gender from two years to three months - or six months for people aged 16 and 17 - with a three-month reflection period during which they can change their mind.
Efforts by some MSPs to keep the minimum age at 18 were voted down, with Social Justice Secretary Shona Robison saying that 16-year-olds have the right to vote in Scottish Parliament elections, leave home and get married.
She added: "Applying for a legal gender recognition generally aligns with the other comparable rights and responsibilities young people obtain at 16."
However the government backed other amendments aimed at ensuring young people understand the process and have received appropriate support.
Ms Robison also insisted that "trans rights are not in competition with women's rights", and that the proposals would be a "significant step forward in creating a more equal Scotland, where trans people feel valued, included and empowered."
Anyone who does obtain a GRC will need to live as their acquired gender for the rest of their life - and could face prosecution if they do not.
Opponents of the proposals fear they could be a danger to women and girls, particularly around the provision of single-sex spaces.
Conservative MSP Russell Findlay tabled an amendment that sought to prevent convicted sex offenders being allowed to change their gender.
The amendment was defeated by 59 votes to 64 with two abstentions - sparking angry scenes in the gallery.
However, the government backed another proposed amendment by SNP MSP Gillian Martin that would mean anyone convicted of a sexual offence who wants to apply for a GRC will need to be fully risk assessed.
If the risk is thought to be too high, their application could be refused.
It follows concerns that predatory men could attempt to change their gender to gain access to female prisons.
There have also been protests over a decision to send a trans woman who has convictions for sexually assaulting young girls to the all-female Cornton Vale prison in Stirling.
Katie Dolatowski was awaiting sentencing after previously admitting assaulting a fellow inmate while in a male prison.
A former governor of Cornton Vale, Rhona Hotchkiss, recently told BBC Scotland that in her experience it was "always an issue to have trans women in with female prisoners".
Seven SNP MSPs voted against the legislation at an earlier stage in the process - including former community safety minister Ash Regan, who resigned ahead of the first parliamentary vote - while two others abstained.
Ms Regan, who has said she will not back the government's bill, spoke during Tuesday's debate to criticise the lowering of the minimum age to 16, saying she believed it was too young for someone to make such a "very profound change".
SNP MSP Kenny Gibson also argued that keeping the age limit at 18 would give young people "time and space to grow" and be better prepared to take the "right decision".
The session began with apparent attempts from the Scottish Conservatives to delay proceedings by tabling four separate amendments to the parliamentary agenda.
Despite the heated debate around the bill, it will almost certainly pass into law in a final vote - which is currently scheduled for Wednesday - given the wide support within the SNP, Greens, Labour and Liberal Democrats.