The Supreme Court rejected a request Tuesday to stop the planned release of 26 Palestinian prisoners, clearing the last hurdle as the inmates prepared to be released at midnight.

Some 1,500 people gathered in Ramallah’s main square to celebrate the release, waving Palestinian and Fatah flags, Ynet news reported.

Palestinian Authority President Mahmoud Abbas is expected to greet the 21 prisoners being released to the West Bank at a welcoming ceremony.

Earlier in the day, five of the inmates being released to Gaza were loaded into a van for the journey from Ofer Prison in the West Bank to the Erez Crossing with the Strip.

In Gaza, some 300 people amassed ahead of the release to welcome the prisoners at the Erez Crossing with Israel, where music blared and dozens of people brandished flags and signs reading “we will never forget our heroes.”

“Today is a day of joy for the family and for all of Palestine,” said Tayser Shubair, whose brother Hazem was jailed in 1994 for the death of an Israeli, according to the Israeli Prison Service. “My brother is a freedom fighter and we are proud of him and we thank the president for his effort to get him out.”

The release, the second in a series of four planned moves as part of US-brokered peace talks with the Palestinians, has raised ire in Israel’s right wing and among victims of terror, and set passions aflame in the cabinet, which approved the move Sunday night over the objections of the Knesset’s hawks.

The court said in a statement that there was no legal reason to stop the release from going forward, as Terror Victims’ Association Almagor had requested.

“The question asked of the Supreme Court was only legal — is there a reason to interfere in the decision to release prisoners as part of the negotiations with the Palestinians,” the statement read.

A similar appeal during the first release in August was also rejected.

The three-judge bench had earlier asked the attorney general’s representative if the midnight deadline for the release was “a flexible matter” but received a negative response.

“The government gave its word, through the Americans, that at the start of the fourth month of negotiations — that is, today — the second stage would be carried out. For security-related reasons, it is necessary to complete the transfer and release at night … we must uphold our obligation,” the lawyer representing the state said.

Naftali Wertzberger, a lawyer working with the bereaved families who submitted the appeal, said a recent spate of attacks on Israelis in the West Bank had changed the playing field.

“The government did not bother to discuss the latest wave of terror in the West Bank over the past few weeks. It’s turning the other cheek even as we’re talking about the second phase of the release,” he said. “Releasing terrorists only adds fuel to the terrorist fire. I’m optimistic and hopeful we’ll stop [the releases].”

Highlighting the opposition to the move, some 50 Israelis protested outside Ofer Prison. They held signs reading “death to murderers” and burned keffiyehs, traditional Palestinian headscarves.

A night earlier, as many as 3,000 demonstrators had gathered there to protest the impending release, which Israel promised to do in exchange for the resumption of negotiations.

Among the demonstrators Monday were family members of the victims of terror attacks perpetrated by some of those slated for release on Tuesday. Demonstrators carried the victims’ pictures, and many of them shouted, “Jewish blood is not cheap.”

Housing and Construction Minister Uri Ariel addressed the demonstration Monday, declaring it was “time to stop” the release of terrorists.

The Israel Prisons Service published the names of the 26 prisoners late on Sunday night. All are convicted murderers. The prisoners were slated for release within 48 hours of the list’s publication.

Six of the inmates have been imprisoned for just under 30 years. All but two were convicted for murders committed before the signing of the 1993 Oslo Peace Accords. A government statement said that 21 of the inmates were from the West Bank and five were from the Gaza Strip.

Among the prisoners to go free is Damouni Saad Mohammed Ahmed, who was convicted in the 1990 killing of IDF reservist Amnon Pomerantz in the Gaza Strip; Pomerantz’s car was set on fire while he was inside. A second convicted murderer of Pomerantz is not among those set to be released.

The release has drawn a great deal of political fire for the prime minister, and led to a spat between coalition partners Bennett and Justice Minister Tzipi Livni (Hatnua party), who is in charge of peace talks with the Palestinians.

In part to offset the political fallout from the release and calm the anger on the right, Prime Minister Benjamin Netanyahu’s office announced that the government would, this week, approve tenders for the construction of 1,200 new apartment units across the Green Line.

On Monday, Netanyahu called the decision to release the prisoners one of the most agonizing of his career.

“The decision to release prisoners is one of the toughest decisions that I’ve taken as prime minister,” Netanyahu told a Likud-Beytenu faction meeting. “I am certain that all the prime ministers who made this decision before me agonized over it as well, due to the injustice of villains being released before they serve the full term of their sentences. My heart is with the bereaved families, and it pains me. This decision is a necessity, given the reality in which we live.”

The Associated Press contributed to this report