If the swap of an Israeli soldier for thousands of Hamas prisoners is completed and is the real deal this time, both sides may benefit.

It was announced on Monday that Gilad Shalit, the Israeli artillery sergeant who was captured by Hamas in a border-crossing raid in June 2006, would be exchanged for more than a thousand Palestinians held by Israel, including top members of the PLO and, according to some reports, Marwan Barghouti, a leader of Fatah, a Hamas rival group. (Other reports have said that Barghouti was not on the list of those slated to be released.)

According to news reports, Prime Minister Benjamin Netanyahu of Israel and Hamas leader Khaled Meshal have agreed on the exchange, setting aside early rumors that it was a false report.

Celebrations were reported in Gaza, where Hamas holds forth, and in Israel, with thousands cheering the news that Shalit would finally be freed.

Meshal said coming to the deal had been “very, very difficult,” but viewed it as a “national accomplishment.” Hamas has long been recognized as a bitter enemy of Israel, which defined them as a terrorist organization.

Netanyahu said Shalit would be free “within days.” He said that when he took office, “I took it upon myself, as a personal mission, to bring Gilad home to his family.”

The timetable for the exchange, which was facilitated by Egypt, begins with Shalit being sent to Egypt, followed by the release of 450 Palestinians. Two months later, according to a news account, the remaining prisoners would be released. None of this has been officially confirmed.

Israel’s benefit, along with the symbolism of Shalit’s release, is an improved relationship with Egypt. Things have not been going well between the two countries since the toppling of Egyptian President Hosni Mubarak and the subsequent raid on the Israeli embassy there.

Hamas has been reeling from the turmoil in Syria, its most important base outside of Gaza. The swap may shore up the organization’s standing in the Arab world and improve its credibility. Moreover, it brings them back in the spotlight, stealing some of the attention from Mahmoud Abbas, the leader of the Palestine Authority, and his bid for nationhood for Palestine.

In any case, there is much to be done before the swap is considered a done deal.