In a much-anticipated prisoner exchange that could have broad implications, Israel and Hamas announced that an Israeli soldier abducted to Gaza five years ago would be swapped for about 1,000 Palestinians held by Israel and accused of militant activity.
Israel's government approved the deal early Wednesday following a three-hour debate after both Israeli Prime Minister Benjamin Netanyahu and Hamas leader Khaled Mashaal announced the agreement in televised comments.
Netanyahu said the captured soldier, Sergeant Gilad Shalit, would return home within days. Mashaal, portraying the agreement as a victory, said the Palestinian prisoners would be freed in two stages over two months.
Hamas and Israel are bitter enemies. Hamas has launched attacks on Israel, killing hundreds, and Israel blockaded Gaza after Hamas seized power there in 2007, carrying out a large-scale invasion in 2009. More than 1,500 Gaza Palestinians have been killed in Israeli raids and airstrikes since the soldier was captured.
In the northern Gaza town of Jebaliya, thousands of Hamas supporters flocked the streets, led by masked militants.
Cars with loudspeakers played praise for Hamas. Thousands of other Gazans rushed to their border with Egypt, clutching Palestinian and Egyptian flags, tossing flowers and cheering.
Gaza's Hamas Prime Minister, Ismail Haniyeh, smiled as he threw candy to celebrating backers.
The deal maintains a decades-long tradition of lopsided exchanges that have come under increasing criticism in Israel, and ends a period of tortured indecision by Israeli governments torn between securing the release of a single soldier and the risk that freed militants might return to violence that could cost many more lives.
"There is built-in tension between the desire to return a kidnapped soldier ... and the need to preserve the security of the citizens of Israel," Netanyahu said, in comments at opening the Cabinet meeting. "I believe we reached the best deal that we can reach at this time, a stormy time in the Middle East." In agreeing to go ahead with the deal, the career hard-liner made a potentially fateful choice.
It gives Hamas, a militant group that rules the Gaza Strip, a victory that might strengthen its hand against the more moderate Palestinian President Mahmoud Abbas, whose Palestinian Authority runs the West Bank.
Mashaal said 1,000 male prisoners and 27 female ones would be released, the first 450 over the next week and the rest within two months. He said the released would include 315 prisoners serving life sentences, suggesting they were convicted of attacks that caused the deaths of Israelis.
Seeming to confirm Israel's fears, Mashaal said that those who are released "will return to ... the national struggle." "This is a national achievement for the whole Palestinian people," Mashaal said, adding that he was pained not to be able to release the thousands of remaining prisoners held by Israel.
The exact number of prisoners is under some contention, with the Palestinians citing 8,000 and Israel confirming about 5,000.
Yoram Cohen, head of Israel's Shin Bet security agency, said over the course of six secret rounds of talks in recent months, Hamas had backed down from key demands, including the release of some top militants. He said about 40 of the first group of prisoners would be exiled to other countries.
News of the deal set off wild celebrations at a protest tent erected by Shalit's family outside Netanyahu's residence in Jerusalem. Several hundred people danced in the street and waved flags with Shalit's image on it.
The soldier's father, Noam, has become a well-known public figure by pushing for his son's freedom.
The tiny structure is decorated with pictures of Shalit, as well as a large sign with the number 1,934, the number of days he has been in captivity. Shalit's parents sat in the tent, smiling as people flooded to the area and cars honked horns in excitement.
But typical of the criticism was a statement by Almagor, a group representing victims of Palestinian attacks. "In the end Netanyahu has surrendered to Hamas," the group said.
"The terrorists who are released are a danger to the citizens of Israel." The plight of Palestinian prisoners is equally emotional among Palestinians. Virtually every Palestinian has a relative who has served time in an Israeli prison, and Palestinians routinely hold large demonstrations where they hold up posters of their imprisoned loved ones.
The very fact of any agreement between Israel and its archenemy seemed to offer a beguiling prospect of a new dynamic in the region.
Neither side hinted at changes in basic policies, the prospect of even lukewarm relations developing between Israel and Hamas could open a new window for peace efforts.
The deal was also an important milestone for the new military authorities in Egypt, which both sides credited with brokering the deal and who emerge with a heightened aura of regional leadership.
Shalit was captured in a cross-border raid in June 2006 by Palestinian militants who burrowed into Israel and dragged him into Gaza after killing two other soldiers.
Little has been known about his fate since then, and Hamas has outraged public opinion in Israel by refusing to even allow Red Cross visits, releasing only a brief audio recording and a videotaped statement early in his five years in captivity.
Shalit's ordeal has become an obsession in Israel, where military service is mandatory and the public has identified with his family. Israel's Channel 2 TV said Shalit would be returned to Israel via Egypt.
Cohen, the Israeli security chief, said there was a turning point in July, when Hamas dropped its demands to free key imprisoned militants. He said the most prominent names, uprising leader Marwan Barghouti, faction leader Ahmed Saadat and Hamas bombmaker Abdullah Barghouti were not included.
Saadat was convicted of planning the assassination of an Israeli Cabinet minister in 2001. Barghouti was the top local commander of Fatah, the movement of President Mahmoud Abbas, when he was arrested in 2002 and convicted of a role in deadly attacks against Israelis. He is serving multiple life terms but is widely touted as a future Palestinian president.
Israel has been carrying out prisoner swaps for decades, including handing over 4,600 Palestinian and Lebanese captives in 1983 in exchange for six captured Israeli soldiers. In 2008, it freed Arab prisoners for the bodies of two soldiers killed by Hezbollah guerrillas in Lebanon.
Hamas is in a bitter rivalry with Abbas, who is enjoying a burst of popularity after defying Israel and the US and seeking membership for the Palestinians at the UN.
Abbas, travelling in South America, praised the deal.
"We've worked very hard for a long time to reach this agreement and reach this objective," Abbas said after meeting Venezuelan President Hugo Chavez. "The Israeli soldier will finally return to his family ... but there are 5,000 jailed Palestinians in Israeli prisons, whose families are impatiently waiting for them."
Netanyahu is also eager for a domestic boost. The Israeli leader has faced growing criticism for a deadlock in peace efforts with the Palestinians, as well as a series of domestic protests over the country's steep cost of living.