Palestinian factions Hamas and Fatah have signed a reconciliation deal after Hamas agreed to hand over administrative control of Gaza, including the key Rafah border crossing, a decade after seizing the enclave in a civil war.
The deal brokered by Egypt bridges a bitter gulf between the Western-backed mainstream Fatah party of Palestinian President Mahmoud Abbas and Hamas, an Islamist movement designated as a terrorist group by Western countries and Israel.
Palestinian unity could also bolster Mr Abbas's hand in any revival of talks on a Palestinian state in Israeli-occupied territory.
Internal Palestinian strife has been a major obstacle to peacemaking, with Hamas having fought three wars with Israel since 2008 and continuing to call for its destruction.
Hamas's agreement to transfer administrative powers in Gaza to a Fatah-backed government marked a major reversal, prompted partly by its fears of financial and political isolation after its main patron and donor, Qatar, plunged in June into a major diplomatic dispute with key allies like Saudi Arabia.
They accuse Qatar of supporting Islamist militants, which it denies.
The Palestinian accord was met warily in Israel.
For Israel to accept it, said one government official, the deal must abide by previous international agreements and terms set out by the Quartet of Middle East peace mediators -including the recognition of Israel and Hamas's giving up its weapons.
"Israel will examine developments in the field and act accordingly," according to the official, who spoke on condition of anonymity.
Thousands of Palestinians took to the streets across Gaza in celebration of the unity pact, with loudspeakers on open cars blasting national songs, youths dancing and hugging and many waving Palestine and Egyptian flags.
Egypt helped mediate several previous attempts to reconcile the two movements and form a power-sharing unity government in Gaza and the West Bank, where Abbas and the Fatah-led Palestinian Authority (PA) are based.
Hamas and Fatah agreed in 2014 to form a national reconciliation government, but the deal soon dissipated in mutual recriminations with Hamas continuing to dominate Gaza.
"The legitimate government, the government of consensus, will return according to its responsibilities and according to the law," Fatah delegation chief Azzam Al-Ahmed said at the signing ceremony in Cairo.
He said the unity government would "run all institutions without exception," including all border crossings with Israel and in Rafah, Gaza's only access point with Egypt.
The agreement calls for Mr Abbas's presidential guard to assume responsibility of the Rafah crossing on 1 November, and for the full handover of administrative control of Gaza to the unity government to be completed by 1 December.
Analysts said the deal is more likely to stick than earlier ones given Hamas's growing isolation and realisation of how hard Gaza, its economy hobbled by border blockades and infrastructure shattered by wars with Israel, was to govern and rebuild.
Deeper Egyptian involvement, believed to have been backed by Saudi Arabia and other Arab states, also helped cement the deal.