* Egyptian mediation helps secure five-day extension to ceasefire
* Talks aimed at longer-term Israeli-Palestinian accord on Gaza
* Obstacles include Gaza 'demilitarisation', push for sea port
By Luke Baker and Nidal al-Mughrabi
JERUSALEM/GAZA, Aug 14 (Reuters) - Israel and the Palestinians have given themselves five days to come up with a comprehensive agreement to end the war in Gaza. While that is a welcome extension on past ceasefires, there is still a dangerously long way to go to bridge their differences.
After agreeing to Egypt's proposal to extend the halt in hostilities until Aug. 18 - a deal clinched with barely an hour to run on the previous, 72-hour pause - Palestinian and Israeli negotiators left Cairo to consult with their leaders.
One Palestinian faction headed for Ramallah, the main city in the West Bank, to meet Palestinian Authority (PA) President Mahmoud Abbas, while some representatives of the Islamist group Hamas flew to Qatar to see Khaled Meshaal, their leader in exile, and others returned to Gaza.
Few precise details of the indirect negotiations have emerged, but the broad outlines are well known: the Palestinians want an end to Israel's blockade of Gaza, an extension of the strip's maritime and security boundaries and the building of a sea port and reopening of an airport in the enclave.
For their part, the Israelis want an end to rocket fire from Gaza, the full demilitarisation of the territory, and for Abbas's PA to take over responsibility for managing Gaza's 12 km (7.5 mile) border with Egypt at Rafah, an effort to prevent the smuggling of weapons and other military-use equipment.
In any negotiation, no party ever ends up getting everything it wants. But perhaps nowhere in the world is it harder to secure compromises than in the Middle East, making Egypt's high-stakes mediation particularly touch-and-go.
While Hamas, which controls Gaza, is likely to accede to the PA taking over administration of the Rafah border, and Israel can agree to loosen maritime restrictions and allow a freer flow of goods into Gaza, steps beyond that become trickier.
Israel has made clear that any discussion of a Gaza sea port is not going to happen now, and Hamas has said it has no intention of disarming. And therein lies the rub.
In an interview this week, Yair Lapid, Israel's finance minister and the leader of its second largest party, called demilitarisation the overriding goal. Without it, the cycle of violence in Gaza - Hamas firing rockets, Israel responding with air strikes - was only likely to continue.
"Our goal is simple: keeping the security interests of Israel, bringing back the PA to Gaza, and then disarmament or demilitarisation of Gaza," Lapid told Reuters.
"We understand that the other side of this equation is the rehabilitation of Gaza."
Israel will not deal directly with Hamas, which it regards as a terrorist organisation. However, after a seven-year rift with Abbas that left it in sole control of Gaza, Hamas signed a unity agreement in April that acknowledges a role for the PA.
At the beginning of the Gaza war, Abbas was critical of Hamas's actions, but Hamas now appears to accept that if it wants to be able to pay public workers and retain influence, it needs to let the PA take back some authority in Gaza, which will help open the purse strings.
With four wars in the past eight years, the most recent having killed 1,945 Palestinians, mostly civilians, as well as 64 Israeli soldiers and three civilians in Israel, recent Gaza history clearly shows the human toll when violence replaces negotiation.
Yet Hamas is equally determined that it cannot and will not give up its arms, which are inherent in the struggle to end what it sees as Israel's occupation of the whole of historical Palestine, not just the West Bank.
"We are a resistance movement. If we accept removing our arms, the very reason for our existence gets negated," said Sami Abu Zuhri, Hamas's spokesman. "Arms of the resistance are linked to ending the occupation of Palestinian lands."
The best that might be hoped in terms of demilitarisation is the end of rocket fire from Gaza, tighter oversight of Hamas's armed wing and other militant groups and more restrictions on who bears arms beyond Gaza's police force.
But even then, any of those steps will be heavily contingent on what steps Israel is prepared to take on the sea port or reconstruction of Gaza's demolished airport.
Without strict monitoring of how goods moving into Gaza are used - for the reconstruction of buildings rather than the digging of a new tunnel network, for example - Israel is likely to be very reluctant to provide more breathing room.
How that monitoring is carried out and by whom is another issue, all of which will have to be painstakingly detailed if trust is to be established on both sides. All the while, one or two loose rockets from Gaza or Israeli troop movements that unsettle Hamas have the potential to reignite the conflict.
That said, after a month of intense fighting - with a huge cost in lives lost, destroyed infrastructure and traumatised families on both sides of the border - there would appear to be little appetite in Israel or Gaza for more bloodshed.
With two 72-hour ceasefires having largely held and a new 120-hour one in place, at least both the Palestinians and Israelis are now intently focused on the nitty-gritty steps needed to secure a longer-lasting peace. (Writing by Luke Baker; Editing by Kevin Liffey)
Our Standards: The Thomson Reuters Trust Principles.