The Israeli Supreme Court on Monday overturned a law allowing illegal immigrants to be detained without trial for three years, declaring it "unconstitutional."
The court ruled that the controversial 2012 legislation, under which 2,000 men, women and children, mostly from Eritrea and Sudan, are interned, ran counter to Israeli human rights law.
Human rights groups say that the majority of the internees cannot be deported because of threats to their lives in their homeland.
In a 124-page ruling, the court ruled that the legislation, which amended a 1954 law originally targeted at Arabs trying to enter Israel, ran counter to a basic law enshrining "human dignity and freedom."
"In the opinion of all nine justices on the panel, the period of three years' detention as stated in the law is unconstitutional," judge Edna Arbel wrote.
Signup to our newsletter and follow us on Facebook and Twitter!
The amendment was passed by parliament in January last year as part of efforts to curb an influx of illegal migrants across the desert border with Egypt.
The Association for Civil Rights in Israel, one of six petitioners in the case, hailed the court's ruling.
"The Supreme Court ruled that administrative detention of this sort violates the Basic Law: Human Dignity and Freedom, and that the state must examine each of the detainees' cases individually within 90 days and release all those who are entitled to release under the Entry to Israel Act," the ACRI said.
In 2012, Israel launched a crackdown on what it said were 60,000 illegal immigrants from Africa, rounding up and deporting 3,920 by the end of the year, and building a high-tech fence along the border with Egypt.
The government said that while 2,295 people crossed the border illegally in January 2012, only 36 got across in the first part of December.
Rising tensions over the growing number of illegal immigrants exploded into violence in May 2012 when a protest in south Tel Aviv turned ugly, with demonstrators smashing African shops and property, and chanting "Blacks out!"