Rival Palestinian factions struck a deal for a ceasefire in Gaza from 3 am (0100 GMT) on Tuesday, aiming to end to the fiercest internal fighting since the Islamist Hamas movement's election victory a year ago.
Foreign Minister Mahmoud al-Zahar, speaking after Prime Minister Ismail Haniyeh of Hamas met a senior aide to President Mahmoud Abbas of Fatah, said the two sides agreed to take all gunmen off the streets of Gaza.
Gunfire still echoed round the narrow coastal strip as Zahar made the announcement after five days of fighting in which at least 30 Palestinians have been killed.
Previous ceasefires, including one last month, have been short-lived.
The violence has derailed unity government talks between Hamas and Fatah and prompted some families in the densely populated territory to flee their homes. Many shops and schools have been closed.
Zahar said the factions agreed to "pull all gunmen from the streets and remove checkpoints, ... return all security forces to their positions and end all forms of tensions".
They also agreed to hand over those suspected of involvement in the killings to prosecutors for investigation, and prevent the bloodshed in Gaza from spilling over to the West Bank.
Zahar was accompanied by Haniyeh, Abbas aide Rawhi Fattouh and an Egyptian security delegation which attended the talks.
"The president and the prime minister call on Hamas and Fatah to abide by the above mentioned agreement and to meet immediately to discuss all the remaining issues in preparation to resume the broad national meeting over the formation of a national unity government," Zahar said.
On Sunday, Saudi Arabia invited the feuding factions for urgent talks in its holy city of Mecca.
Both sides agreed to attend the meeting but no date was set, and the two sides spent much of Monday trading blame for the clashes.
Hamas accused Mohammad Dahlan, a Fatah strongman and security adviser to Abbas, of inciting the violence, a charge Fatah rejected.
Explosions and gunshots echoed across Gaza through the day.
A Hamas militant and a policeman loyal to Fatah died in separate gunbattles, hospital and security officials said.
A 20-year-old Palestinian was also shot dead near the scene of one of the fiercest clashes.
On Monday night, a rocket-propelled grenade was fired at a police station in Gaza City.
The attack, which a security source blamed on Hamas, was followed by bursts of heavy gunfire. There were no immediate reports of casualties.