* Talks on a longer-term ceasefire under way in Cairo
* Israel ready to extend truce past Friday deadline
* Hamas insists demands must be met or fighting could resume (Adds Hamas armed wing statement, updates Gaza death toll)
By Nidal al-Mughrabi and Lin Noueihed
GAZA/CAIRO, Aug 7 (Reuters) - Mediators worked against the clock on Thursday to extend a truce between Israel and Palestinian militants in the Gaza Strip, as the three-day ceasefire entered its final hours.
Israel said it was ready to agree to an extension as Egyptian go-betweens pursued talks with Israeli and Palestinian delegates in Cairo on ending a war that has devastated the Hamas-controlled enclave.
Palestinians want an Israeli-Egyptian blockade on Gaza lifted and prisoners held by Israel to be freed. Hamas's armed wing said it was ready to resume fighting unless Palestinian demands were met, and Israel said it would respond forcefully if attacked.
"Indirect talks are ongoing and we still have today to secure this," an Egyptian official said when asked whether the truce was likely to go beyond Friday's 8 a.m. (0500 GMT) deadline.
"Egypt's aims are to stabilise and extend the truce with the agreement of both sides and to begin negotiations towards a permanent agreement to cease fire and ease border restrictions."
The Palestinian delegation met Egyptian intelligence officials late on Thursday. Israeli officials said Israel's delegates would return to Cairo in the evening having briefly returned home to confer with Prime Minister Benjamin Netanyahu.
After a month of bitter battles, the two sides are not talking face to face.
Gaza officials say the war has killed 1,875 Palestinians, most of them civilians. Hamas said on Thursday it had executed an unspecified number of Palestinians as Israeli spies.
Israel says 64 of its soldiers and three civilians have died in the fighting that began on July 8, after a surge in Palestinian rocket salvoes into Israel.
An Israeli official said late on Wednesday that Israel "has expressed its readiness to extend the truce under its current terms" beyond Friday morning's expiry of the three-day deal, which took effect on Tuesday and has so far held.
A senior Israeli minister, Yaakov Peri, said on Army Radio that an extension would be "right for both sides" and added: "Let's hope that reason prevails."
In Gaza, Palestinian factions held a rally, with several thousand supporters urging Hamas to "bomb Tel Aviv".
Mushir Al-Masri, a Hamas official, told the crowd that Israel should know that "our fighters are in the battlefield with their fingers on triggers".
Hamas's armed wing called on Palestinian negotiators to quit the talks in Cairo unless progress were made towards meeting the group's demands, which include opening Gaza's seaport.
"We urge the Palestinian delegation negotiating not to renew the truce except after the acceptance in principle, particularly to establish the seaport, and if there is no acceptance then we ask the delegation to withdraw from talks," the armed wing's spokesman, Abu Ubaida, said in a televised statement.
"We are ready to enter the battle anew and we will give the occupation a difficult decision to make: either we will bring them into a long war of attrition or we will draw them into a broad territorial war," he added, threatening attacks he said would paralyse the Israeli economy and shut down Ben Gurion International Airport near Tel Aviv.
A Hamas refusal to extend the ceasefire could further alienate Egypt, whose government has been hostile to the group and which ultimately controls Gaza's main gateway to the world, the Rafah border crossing.
Israel's military chief, Lieutenant-General Benny Gantz, said that if Hamas broke the truce, Israel would use "whatever force necessary to ensure the security of Israeli citizens".
A senior Israeli military officer, briefing foreign reporters, said Hamas was capable of resuming attacks with its remaining rockets but it could take "months" for guerrillas to replenish their arsenal from domestic production facilities battered by Israel's assault.
"They started with around 9,000 rockets (in their total arsenal) and now they have a bit less than 3,000," the officer said. "The majority are short-range, less than 40 km (25 miles)."
Israel's central bank governor, Karnit Flug, put the war damage to the Israeli economy at $1.44 billion and Finance Minister Yair Lapid said the 2014 budget could absorb the cost of the conflict without raising taxes. But the Fitch ratings agency said budget planning next year might reflect the need to reverse recent falls in defence spending.
Israel withdrew ground forces from Gaza on Tuesday, shortly before the truce began. There were signs it expected the quiet to last, as emergency restrictions on civilians living near Gaza in Israel's south were lifted to permit more public activities. Residents were urged to resume their routines.
The Israelis described the ceasefire as a tradeoff of "calm for calm". They have shown little interest in easing their naval blockade of Gaza and controls on overland traffic and airspace, worrying Hamas could restock on weapons from abroad.
In Gaza, where half a million people have been displaced by a month of bloodshed, some residents left U.N. shelters to return to neighbourhoods devastated by Israeli shelling.
U.S. President Barack Obama, backing efforts to broker a durable ceasefire, called for a longer-term solution that provides Israel with security while offering Gaza residents hope they will not be permanently cut off from the world.
While condemning Hamas for launching rockets against Israel from population centres, Obama urged an eventual formula to ease the hardships of ordinary Palestinians.
Efforts to achieve a lasting truce could prove difficult, with the sides far apart on their central demands, and each rejecting the other's legitimacy. Islamist Hamas calls for the Jewish state's destruction, while Israel denounces Hamas as a terrorist group and refuses any direct contact.
(Additional reporting by Stephen Kalin and Maggie Fick in Cairo, Ali Sawafta in Ramallah, Allyn Fisher-Ilan and Ori Lewis in Jerusalem; Writing by Giles Elgood in Jerusalem; Editing by Jeffrey Heller and Andrew Roche)
Our Standards: The Thomson Reuters Trust Principles.