After 119 years, more than 70 hours of debate, protests and threats of a leadership spill and party rebellion, abortion has been decriminalised in NSW.
There was applause in the lower house as the Abortion Law Reform Act 2019 passed its final hurdle, a week after Premier Gladys Berejiklian faced down a mutiny from rebel Liberal MPs.
The state's upper house passed the bill 26 votes to 14 on Wednesday night following 40 hours of discussion, making it the third-longest debate in the house of review.
All that was needed was the lower house to agree to a number of key amendments, including on late-term and sex-selective abortions, to overturn the state's 119-year-old law.
Labor MP Jo Haylen, who co-sponsored the bill, described the vote as "a historic day".
"This is about making sure women can make choices and that they can get a procedure which is health care," she told reporters on Thursday.
"No longer will women be criminalised for making that choice and that's a wonderful thing."
The bill, presented to parliament by Independent MP Alex Greenwich, takes abortion out of the criminal code and allows terminations up to 22 weeks as well as later abortions if two doctors agree.
The bill was opposed by religious groups, anti-abortion activists and several MPs who raised concerns about late-term and sex-selective abortions, conscientious objection and the way the bill was introduced.
Tensions reached a climax last week when Liberal MPs Tanya Davies, Matthew Mason-Cox and Lou Amato threatened, then withdrew, a leadership spill motion against Ms Berejiklian over her handling of the bill.
Ms Davies and another Liberal MP Kevin Conolly had also threatened to move to the crossbench - but on Thursday they said they would remain with the government.
Mr Conolly told reporters it was a sad day for the state, and he was aggrieved and disappointed over the passage of the bill, but said it was in better shape than eight weeks earlier.
Ms Davies said they had needed to respond in "such strong and determined fashion" after being presented with a "flawed process" and a bill which "went far further" than decriminalising abortion.
"At the end of this process we have achieved a better bill," she said.
"We certainly have achieved concessions around sex-selection abortions, babies born alive, doctors' conscientious objection as well as continuing the common-law provisions around late-term abortions."
Mr Greenwich said none of the amendments created any new barriers for women to access safe and legal abortions in NSW.
One of the amendments states the NSW parliament opposes sex-selective abortions but has not banned it, with a future report to include prevention recommendations.
Doctors performing abortions after 22 weeks can seek advice from a multi-disciplinary team or hospital advisory committee, while practitioners who have a conscientious objection can refer a patient back to NSW Health.
And doctors must provide appropriate care to babies born alive after a termination.
Labor MP Penny Sharpe, another co-sponsor of the bill, said it was "a massive step forward for women in NSW" and long overdue.
Abortions have already been decriminalised in Western Australia, Victoria, Tasmania, Queensland, the Northern Territory and the ACT, and are legal for some medical reasons in South Australia.
After a horror few weeks, Ms Berejiklian was not present for the final vote on Thursday, telling reporters she was too busy to be in the chamber to vote.
"I had to run the state," she said.
"When I'm required to be in the chamber I am, and I had full confidence that the house would resolve it in a positive way."
Sydney's Catholic Archbishop Anthony Fisher described the vote as "a very dark day for NSW".
"The new abortion law is a defeat for humanity," he said in a statement.
"Since the abolition of capital punishment in New South Wales in 1955, this is the only deliberate killing ever legalised in our state."
Australian Associated Press