Apparently it was fireworks, not just stray rounds of ammunition, lighting the night sky over Gaza this morning (Australian time) in celebration at the announcement that rival Palestinian leaders, president Mahmoud Abbas and Hamas chief Khaled Meshaal, had reached an agreement to end their fighting and establish a government of national unity.

The leaders of Fatah and Hamas had promised to stay in Mecca until a deal was finalised, but it came quicker than expected.

It’s a long time since there’s been much cause for celebration in the Palestinian territories. The Hamas government of prime minister Ismail Haniya, elected a year ago, has been boycotted by both Israel and the United States, and the cycle of violence, poverty and dysfunctional administration has only gotten worse.

The US has tried to build up Fatah as a counter to Hamas, despite the fact that Hamas has done a better job in recent months of observing the ceasefire with Israel. The American motto appeared to be “millions for civil war, not one cent for public services”, although, as this morning’s Age reports, American aid could be a kiss of death in Palestinian politics.

But violence doesn’t always lead to a downward spiral. Sometimes an outbreak of unexpectedly bloody conflict has the opposite effect: it makes both sides step back from the brink and decide that there has to be a better way. (As happened, for example, in New Caledonia in the 1990s.)

Of course, it could all fall apart. There is still no explicit recognition of Israel from Hamas – although it will “respect” previous agreements – and that will be used by hard-liners as an excuse to continue the boycott. (The US was non-committal on the subject this morning.)

But if you really believe your opponent is intransigent, you have nothing to lose by trying the path of negotiation. At worst, you’ll be proved right and display the high moral ground. At best, you might be wrong and find that agreement is possible after all. That’s a message that Hamas and Israel both need to take on board.