An Israeli solider captured and held by Hamas for five years may soon be back home, thanks to a tentative agreement that would also see more than 1,000 Palestinian prisoners go free.

On Tuesday, Israeli Prime Minister Benjamin Netanyahu announced that Sgt. Gilad Shalit will be exchanged in return for hundreds of Palestinian prisoners, some of whom have been convicted of deadly attacks against the state.

"If all goes according to plan, Gilad will be returning to Israel in the coming days," Netanyahu said.

The deal comes after five years of slow and difficult negotiations that have weighed heavily on the strained relations between Israel and Hamas.

Hamas used Shalit as a key bargaining tool, causing anger among Israelis who believed that his human rights were being compromised. Likewise, the captivity of Palestinians in Israel is a sensitive issue among Palestinians.

In the northern Gaza town of Jebaliya, thousands, including masked militants, took to the streets in a show of support for Hamas.

Gaza's Hamas prime minister, Ismail Haniyeh, threw candy to his supporters in the crowd there.

Netanyahu countered criticism of the deal by saying that he understands the pain and anger of Israelis who have been touched by violence. But he stressed that given the current climate in the region, negotiators secured "the best deal we could get."

"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 at a Cabinet meeting. "I believe we reached the best deal that we can reach at this time, a stormy time in the Middle East."

Hamas has also confirmed the deal, which was initiated last Thursday and was pushed by Netanyahu Tuesday during a hastily arranged Cabinet meeting.

The prisoner exchange includes many Palestinians convicted in Israeli courts of deadly attacks. Hamas has not backed off its ideology that calls for the destruction of the Jewish state.

Hamas leader Khaled Mashaal said 1,000 male prisoners and 27 female prisoners are to be released, starting with 450 this week.

The deal marks a shift for Israel, which had previously turned down overtures from Hamas precisely because the Palestinian group was calling for the release of convicted militants.

Exact details of the deal were not immediately known, but previous sticking points had been whether or not the freed Palestinians would be allowed to return home to Gaza and the West Bank.

One potential deal would see the Palestinians go free, but would bar them from the Palestinian territories and force them into exile elsewhere.

Shalit was captured in June 2006 during a cross-border raid by Palestinian militants who had burrowed into Israeli territory. Shalit was then dragged back to Gaza and held by his captors, who released very little information about the young soldier.

Hamas has caused outrage among the Israeli public as they have not even allowed Red Cross visits to Shalit.

Israel Kasnett of the Jersualem Post says little is known about the state of Shalit's health. He was seen in a 2009 video "looking somewhat frail and weak but overall, healthy."

"That's the first and main evidence that he was mostly healthy," he told Â鶹´«Ã½ Channel.

Ezzat Rishq, a Hamas official who was in Cairo with a delegation of party staff on Tuesday, also confirmed the deal.

With files from The Associated Press