* Sides say prolonged ceasefire provides more negotiating time
* Egypt urged the extension shortly before truce was set to expire (Recasts with agreement reached to extend truce)
By Nidal al-Mughrabi and Stephen Kalin
GAZA/CAIRO, Aug 18 (Reuters) - Israel and the Palestinians agreed on Monday to extend a Gaza truce by another 24 hours, minutes before an Egyptian-brokered ceasefire was set to expire, officials on both sides said.
Agreement was reached as gaps on key issues continued to dog efforts to achieve a long-term deal between Israel and militant groups in the Gaza Strip, dominated by Hamas Islamists, which would allow reconstruction aid to flow in after five weeks of fighting.
The monthlong war ended in effect more than a week ago when Egypt brokered a three-day truce, which it then won agreement to extend by another five days through 2100 GMT on Monday.
A Palestinian official close to the talks in Cairo said the latest extension would give both sides time "to complete the negotiations".
An Israeli official and a security source said in Jerusalem that "on Egypt's request the ceasefire shall be extended by 24 hours to allow further negotiations".
In Gaza a senior Palestinian official said agreement had been reached on all but two points drafted by Egypt for a wider deal, including opening Gaza's crossing to allow a freer flow of goods, and extending maritime limits in the Mediterranean Sea.
Issues still not agreed upon include Hamas's demands to open a seaport and an airport, which Israel has said it would only discuss at a later stage, in addition to freeing Palestinian prisoners held by Israel and Hamas handing over remains of two Israeli soldiers killed in the war, a Palestinian official said.
Israel made clear before the earlier truce lapsed it would continue to hold its fire as long as Palestinians did the same.
"If they shoot at us, we will respond," Justice Minister Tzipi Livni, a member of Prime Minister Benjamin Netanyahu's security cabinet, told Israel Radio.
The Palestinian Health Ministry put the Gaza death toll at 2,016 and said most were civilians in the small, densely populated coastal territory. Sixty-four Israeli soldiers and three civilians in Israel have been killed.
Hamas seeks the construction of a Gaza sea port and the reopening of an airport destroyed in previous conflicts, as part of any enduring halt to violence. Livni said such issues should be dealt with at a later stage.
Israel, which launched its offensive on July 8 after a surge in Hamas rocket fire across the border, has shown scant interest in making sweeping concessions, and has called for the disarming of militant groups in the enclave of 1.8 million people.
Hamas has said that laying down its weapons is not an option.
In Jerusalem, the Shin Bet internal security agency said it had arrested 93 Hamas activists in the occupied West Bank over the past three months who had planned to carry out "serious attacks" in Israel, aiming to destablise the region and eventually topple the Western-backed Palestinian Authority.
The Shin Bet allegations of a planned coup, in a statement that said Israeli authorities had confiscated 30 guns, seven rocket launchers and $170,000 from the group, were met with scepticism by Israeli media commentators.
"Would they have been able to do this? I don't know," Roni Daniel, the well-connected military affairs correspondent for Israel's Channel Two television, said on-air.
Barak Ravid, the Haaretz newspaper's diplomatic affairs reporter, tweeted: "Israeli Shin Bet claims Hamas tried to take over the West Bank with 6 pistols, 7 RPG launchers and 20 M16 guns. Yeah right."
The Gaza offensive has had broad public support in Israel, where militants' rockets, many of them intercepted by the Iron Dome anti-missile system, have disrupted everyday life but caused little damage and few casualties. By contrast, Israeli bombardment of Gaza has wrought widespread destruction.
The United Nations said 425,000 people in the Gaza Strip have been displaced by the conflict.
Israel and Hamas have not met face-to-face in Cairo, where the talks are being held in a branch of the intelligence agency, with Egyptian mediators shuttling between the parties in separate rooms. Israel regards Hamas, which advocates its destruction, as a terrorist group.
In Gaza, Pierre Krähenbühl, head of the United Nations Relief and Works Agency, said he hoped ceasefire talks would lead to substantial change on the ground.
"There has to be a message of hope for the people of Gaza, there has to be a message for something different, there has to be a message of freedom for the people, freedom to move, freedom to trade," Krähenbühl told reporters. (Additional reporting by Allyn Fisher-Ilan in Jerusalem, Maggie Fick in Cairo; Writing by Jeffrey Heller in Jerusalem; editing by Ralph Boulton)
Our Standards: The Thomson Reuters Trust Principles.