Israel’s Supreme Court overruled an entry ban on an American student accused of supporting a boycott campaign of Israel, ruling that her detention was an “extreme and dangerous step”.

Lara Alqasem, 22, who is of Palestinian descent, was detained on entry to Israel on her way to start a master’s degree programme at Jerusalem’s Hebrew University.

The scholarship-winning graduate student was not permitted to clear immigration on 2 October despite having a visa, on the grounds she supported the pro-Palestinian Boycott, Divestment and Sanctions (BDS) movement against Israel.

She decided to stay in Israel and challenge the ban, despite being ordered to return to the United States.

She has been held at the airport since then, making her detention one of the longest for a boycott-related case.

On Thursday a three-judge panel upheld her appeal against the ban, saying her actions did not sufficiently contradict the law and detaining her appeared motivated by disagreement with her political beliefs.

“The inevitable impression is that invalidating the visa given to her was due to the political opinions she holds,” read the verdict. “If this is truly the case, then we are talking about an extreme and dangerous step, which could lead to the crumbling of the pillars upon which democracy in Israel stands,” it added.

A spokeswoman for the immigration authority said she was released from the holding facility on Thursday evening.

Ms Alqasem said she was “relieved” and thanked her “tireless lawyers” as well as her supporters.

In March 2017, Israel's parliament passed a law banning the entry of supporters of BDS, a movement inspired by an international campaign against apartheid in South Africa. Ms Alqasem had been the president of a chapter of Students for Justice in Palestine (SJP) at the University of Florida, which has supported boycotts of Israel in the past.

Ms Alqasem says she left the SJP in 2017 and is no longer part of the BDS movement.

The case has thrown a light on the contentious topic of BDS and Israel’s handing of its critics.

Ms Alqasem's lawyer Yotam Ben Hillel argued that if she intended to boycott Israel she would not want to enter the country.

The court ruled that denying her entry did not to advance the “purpose of the law” but rather harmed Israeli academia.

Many heralded the ruling as a victory for freedoms and an indicator of the impartiality of the judicial system, but interior ministry officials said it dealt a blow.

We are talking about an extreme and dangerous step, which could lead to the crumbling of... democracy in Israel stand Israeli Supreme Court ruling

Israeli Interior Minister Arie Deri, whose ministry looks after the immigration authority, vowed to prevent a ruling like this in the future.

"The decision to allow the student who openly acts against the state of Israel to remain in the country is a disgrace," he tweeted.

"I shall look into how to prevent such a thing happening again," he added.

Gilad Erdan, Israel’s Strategic Affairs Minister told The Jerusalem Post that “the court unfortunately granted a big victory to BDS”. He said the ruling would make it harder to fight activists who support boycotts of the country in the future.

Lawyer Ben Hillel said he hoped that the authorities would reconsider its policy.

'Israel should not be upset': Paraguay moves embassy back to Tel Aviv from Jerusalem

"Israel has the right to control its borders, but that right does not give the ministry of the interior unchecked power to turn away anyone it deems unwanted," he wrote in a statement.

"Lara's case proves that thought-policing has no place in a democracy."

Hebrew University said it looked forward to “welcoming our newest student”.