Belfast's Court of Appeal has ruled it is not up to the courts to decide on abortion law in Northern Ireland, but up to the Stormont assembly.
In 2015, the High Court ruled the NI law breached the European Convention on Human Rights by not allowing abortion in cases of fatal foetal abnormality or sexual crime.
The justice department and the NI attorney general challenged the ruling.
Northern Ireland's abortion law is much stricter than the rest of the UK.
On Thursday, three appeal judges allowed an appeal against the lower court's ruling that abortion legislation was incompatible with the UK's Human Rights Act obligations.
However, in an unusual move, the court invited legal submissions for the case to go to the Supreme Court.
It ruled it was not up to local government, and not the courts, to decide on abortion law.
It said the complex moral and religious questions behind the issue should be determined by a legislature.
The Northern Ireland Human Rights Commission said it was disappointed by the ruling.
Unlike the rest of the UK, abortion is only permitted in Northern Ireland if a woman's life is at risk or there is a permanent or serious risk to her mental or physical health.
It is unlawful to perform a termination of pregnancy, under section 58 of the Offences against the Person Act 1861, unless on these grounds.
The punishment for breaking the law is life imprisonment.
Right to privacy
The original case was brought by the NI Human Rights Commission (NIHRC). It cross-appealed and re-introduced all of the original grounds it brought before the High Court.
One woman's story
In 2013, Sarah Ewart travelled to England for a termination after doctors said her unborn child had no chance of survival outside the womb.
Such a diagnosis, known as fatal foetal abnormality, is not grounds for a legal abortion in Northern Ireland.
Speaking to BBC News NI's Talkback programme, Sarah said Appeal Court ruling was "totally devastating" but she would not give up.
She said she was, however, encouraged by the court inviting legal submissions for the case to go to the Supreme Court.
That court agreed that women's rights to privacy and bodily autonomy under Article 8 of the European Convention on Human Rights were breached.
However, the High Court did not find that the existing abortion law breached Article 3, which protects people from torture or inhuman and degrading treatment, or that it breached Article 14, which covers discrimination.
'No life to protect'
In January 2016, both the Department of Justice and the Attorney General appealed against the High Court judgment.
The Department of Justice argued there was a lack of legal certainty in it which could lead inadvertently to abortion on demand.
It also argued that the ruling on sexual crime was unclear.
The Attorney General said Judge Horner was clearly wrong in his decision when he said "there was no life to protect".
He also argued that there was no proper basis for a doctor to say a foetus had a fatal abnormality.
MPs' amendment call
The letter followed the Speaker selecting an amendment to the Queen's Speech relating to access to abortions.
It calls on the government to allow women in Northern Ireland to have abortions for free in England, instead of being charged as they are now.
More than 50 MPs from all the major parties have signed the amendment, co-ordinated by Labour's Stella Creasy.
The concession came ahead of a vote on the issue in the Commons.
Analysis, BBC News NI Health Correspondent Marie-Louise Connolly
This is a mixed day for Northern Ireland's abortion campaigners - on both sides of the argument.
Overthrowing the previous ruling came as a shock to the Northern Ireland Human Rights Commission and Amnesty International.
While they had claimed victory in 2015 for moving the local abortion story closer in line with the rest of the UK - on Thursday, they said, all that was undone.
Meanwhile, as anti-abortion campaigners were celebrating at that decision - their feelings quickly turned to absolute dismay and disbelief as the news emerged from Westminster.
Earlier this month, the UK's highest court narrowly rejected an appeal by a mother and daughter for women from Northern Ireland to receive free abortions on the NHS in England.
The Supreme Court clarified that restrictions on NHS-funded abortion care for Northern Ireland women are not due to economic or legal constraints.
Rather, they are based on the secretary of state's political considerations and respect for the local assembly.
In a separate case, a judicial review is due to take place in the autumn into the decision to criminally prosecute a woman who allegedly bought abortion pills online for her daughter.
The woman, who cannot be named, is accused of procuring and supplying poison in 2013 with the intent to procure a miscarriage contrary to the 1861 Offences Against the Person Act.