Claps erupted in the NSW upper house as a bill to decriminalise abortion was finally passed after a marathon debate, but its amendments are yet to be approved by the lower house.
The bill passed 26 votes to 14 on Wednesday night after MPs earlier in the day resolved to sit for as long as it took for debate to finish.
It was debated for nearly 40 hours, making it the third longest debate in the NSW upper house.
More than 100 amendments were discussed with the private member's bill to return to the lower house on Thursday before it becomes law.
The bill, presented to parliament in August by Independent MP Alex Greenwich, takes abortion out of the criminal code.
"With the passage of this bill abortion will be decriminalised in NSW - I am sorry that has taken us so long," Mr Greenwich said in a statement on Wednesday night.
The bill also allows terminations up to 22 weeks as well as later abortions if two doctors agree.
Upper house MPs on Wednesday night passed an amendment that recognised doctors performing abortions after 22 weeks can seek advice from a multi-disciplinary team or hospital advisory committee.
Labor MP Penny Sharpe, who is one of 15 co-sponsors of the bill, on Wednesday night said the vote was 119 years in the making.
"The current law has meant women and doctors have a threat of 10 years in jail for making this decision and that not okay," she told parliament.
"This is a massive step forward for women in this state."
The draft legislation has been 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, Mathew Mason-Cox and Lou Amato said they would move a leadership spill motion against Premier Gladys Berejiklian over her handling of the bill.
The rebel MPs, who ultimately withdrew the motion, said it had been made clear to the premier that "at an absolute minimum" four key amendments were required to the bill to ensure continued Liberal Party membership.
The amendments included a ban on sex-selective abortions and stricter regulation of late-term abortions.
Mr Mason-Cox said there has been "significant improvement" to the bill through amendments but declared it "dangerous".
"This bill is dangerous. It lacks proper safeguards. It totally ignores the rights of an unborn child particularly in the case of late term abortions," he told parliament on Wednesday.
Mr Amato raised similar concerns and noted some MPs put their "careers on the line" in the hope of defeating some of the more controversial elements of the bill.
Amendments passed in the upper house include one clarifying that doctors must provide appropriate care to babies born alive after a termination.
Another states the NSW parliament opposes sex-selective abortions, and a future report on the issue is to include prevention recommendations.
The lower house is expected to deal with the bill as the first item of business on Thursday.
Australian Associated Press