The case was taken by the Northern Ireland Human Rights Commission in a bid to allow women and girls to access abortion in cases of rape, incest, or where their baby has no chance of survival, without facing criminal charges.
"Today's result is historic, and will be welcomed by many of the vulnerable women and girls who have been faced with these situations," Les Allamby NIHRC chief commissioner said in a statement.
Unlike the rest of the United Kingdom, the law in Northern Ireland currently bans abortion unless it is required to save a woman's life or if there is a serious risk to her health.
The ruling does not change the law and any reform has to be debated by the regional parliament, where there is significant political opposition.
Judge Mark Horner told the court that "rights of women in Northern Ireland who are pregnant with fatal foetal abnormalities or who are pregnant as a result of sexual crime are breached" by the current law.
He was referring to Article Eight of the European Convention on Human Rights, which covers the right to family and private life.
Judge Horner said that in cases where a foetus cannot survive outside the womb "there is no life to protect".
He added that prohibiting abortion in cases of assault "completely ignores the personal circumstances" of innocent victims of crimes.
"She has to face all the dangers and problems, emotional or otherwise, of carrying a foetus for which she bears no moral responsibility and is merely a receptacle to carry the child of a rapist and/or a person who has committed incest, or both," Horner said.
The Department of Justice did not immediately respond to a query on whether it would appeal the decision.
The court received a submission from Sarah Ewart, a woman who travelled from Northern Ireland to England to have an abortion because her foetus had a severe brain malformation that meant it would either die during pregnancy or once born.
The case also considered submissions from Catholic clergy, anti-abortion groups and human rights organisation Amnesty International.
But anti-abortion campaigner Bernadette Smyth expressed disappointment with decision.
"We must protect the rights of the unborn child," the director of lobby group Precious Life said.