The two main Palestinian factions, the Islamist movement Hamas and its rival, Fatah, announced Thursday that they have reached an agreement to allow the Palestinian Authority to return to the Gaza Strip and run the government there for the first time in seven years.

After two days of talks in Cairo, Hamas — which violently wrested control of the strip in 2007 — agreed to step aside and allow President Mahmoud Abbas and technocrats in the Palestinian Authority to administer civil affairs in the war-ravaged coastal enclave.

The deal could ease the constant infighting between the factions, allow for the rebuilding of the Gaza Strip after seven weeks of war with Israel and see Hamas yield — at least temporarily — its control of the strip.

In the past, however, agreements between Hamas and Fatah have quickly fallen apart.

The accord was brokered by the head of the Egyptian intelligence services, and it stresses the need for the Palestinian Authority “to accelerate the exercising of its security duties” in Gaza.

It remains to be seen whether Hamas, which controls the Gaza police force, will allow the authority, dominated by Abbas’s Fatah party, to take full control. The accord also is silent on what might happen to Hamas’s militant wing.

The two sides stressed the need for the Palestinian Authority to quickly facilitate the rebuilding of Gaza after the war, in which tens of thousands of homes were destroyed. Delegates to the negotiations said that the authority would operate the Gaza side of border crossings with Israel.

The deal allows the Palestinians to resume talks with Israel next month on a permanent cease-fire in Gaza. The Palestinians are seeking an end to Israel’s partial blockade of the strip, which Israel imposed after Hamas — a group it considers a terrorist organization — took over Gaza. The Israelis want the strip demilitarized.

Hamas agreed to a similar deal in the spring but never ceded power in Gaza.

For the past seven years, the Palestinian people have effectively been governed by two groups — Hamas in Gaza and Fatah in the West Bank.

Abbas, who has renounced violence as a means to end the Israeli-Palestinian conflict, criticized Hamas for firing rockets at Israel and accused it of needlessly prolonging the Gaza war, which lasted 50 days. More than 2,100 Palestinians were killed in Israeli bombardments. Some 73 Israelis, mostly soldiers, were killed by Hamas rockets and fighters.

In the war’s aftermath, Abbas accused Hamas of stubbornly running a “shadow government.” Hamas leaders said Abbas had abandoned Gaza and refused to pay salaries owed to 45,000 civil employees hired by Hamas.

The new accord said the authority would pay the salaries and treat the employees with “fairness.”