The announcement caps five years of painful negotiations that have repeatedly collapsed.
The deal would bring home Sergeant 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.
Israel’s Prime Minister, Benjamin Netanyahu, convened an urgent meeting with his cabinet to approve the deal, said an Israeli official.
A senior Hamas official in Cairo also confirmed the deal.
The agreement would exchange Sgt Schalit, 25, for around 1,000 Palestinian prisoners.
Israel had previously refused to consider Hamas’s demands because some of the prisoners are serving lengthy sentences for deadly attacks on Israelis. Exact details of the deal were not immediately available.
A Hamas delegation led by a top Hamas official, Mahmoud Zahar, had arrived in Cairo on Monday night from the group’s headquarters in Syria.
The deal would be implemented in a week, the senior Hamas official said.
Sgt Schalit’s plight has captured the attention of Israel, where military service is mandatory for Jewish citizens and families identify with the Schalit family’s pain.
The soldier’s father, Noam, has become a well-known public figure by leading a campaign to win his son’s freedom, leading demonstrations and sleeping in a tent outside Netanyahu’s residence.
Likewise, the plight of Palestinian prisoners is deeply emotional among Palestinians. Virtually every Palestinian has a relative who has served time in an Israeli prison.
Netanyahu said Sgt Schalit will be home in the “coming days”. He said a deal with Hamas was initialled last Thursday and signed yesterday.
Netanyahu said he got “the best deal we could get” given the turmoil in the region.