JERUSALEM – Israel and Hamas have reached a deal to free a captured Israeli soldier held in the Gaza Strip in exchange for more than 1,000 Palestinian prisoners, both sides said Tuesday, capping five years of painful negotiations that have repeatedly collapsed amid fingerpointing and violence.

The deal, brokered by the new Egyptian government, would bring home Sgt. Gilad Schalit, who was captured in a cross-border raid in June 2006 by Palestinian militants who burrowed into Israel and dragged him into Gaza. Little has been known about his fate since then.

Hamas and Israel are bitter enemies. Hamas has sent dozens of suicide bombers into Israel, killing hundreds of people, and Israel blockaded Gaza after Hamas seized power there in 2007, carrying out a large-scale invasion in 2009 to try to stop daily rocket attacks on Israel.

Israel’s prime minister, Benjamin Netanyahu, convened an urgent Cabinet meeting Tuesday night to approve the deal.

“Gilad will return to Israel in the coming days,” Netanyahu declared in a nationally televised address before entering the meeting.

Effusively thanking Egyptian mediators, he said the deal was signed earlier in the day after being initialed last Thursday.

In Cairo, Egypt’s state TV said Egypt succeeded in sealing the exchange. An Egyptian security official described his government’s role as the guarantor of the deal.

In Damascus, Hamas’ supreme leader, Khaled Mashaal, confirmed the deal, saying a total of 1,027 Palestinian prisoners would be freed in two phases. He said Israel would free 450 prisoners within a week, with the remainder released in two months.