* Ceasefire began at 8 a.m. (0500 GMT)
* Gaza hospital says 40 killed by Israeli shells
* Israel accuses militants of violating truce
* Longer-term truce to be discussed in Cairo
* Israel says tunnel destruction operation continuing (Adds hostilities)
By Nidal al-Mughrabi and Jeffrey Heller
GAZA/JERUSALEM, Aug 1 (Reuters) - A Gaza ceasefire crumbled only hours after it began on Friday, with at least 40 Palestinians killed by Israeli shelling and Israel accusing militants of violating the U.S.- and U.N.-brokered truce by firing rockets and mortars.
The 72-hour break announced by U.S. Secretary of State John Kerry and U.N. Secretary-General Ban Ki-moon was the most ambitious attempt so far to end more than three weeks of fighting, and followed mounting international alarm over a rising Palestinian civilian death toll.
The ceasefire was to be followed by Israeli-Palestinian negotiations in Cairo on a longer-term solution.
Israel launched its offensive in Hamas Islamist-dominated Gaza on July 8, unleashing air and naval bombardments in response to a surge of cross-border rocket attacks. Tanks and infantry pushed into the territory of 1.8 million on July 17.
Gaza officials say at least 1,499 Palestinians, mostly civilians, have been killed and 7,000 wounded. Sixty-one Israeli soldiers have been killed and more than 400 hurt. Three civilians have been killed by Palestinian rockets in Israel.
Some two hours after the truce went into effect, Israeli tanks and artillery opened fire in the southern Rafah area, and a local hospital said 40 people were killed.
The Israeli military had no immediate comment but media reports said the shelling began after Hamas fighters exchanged fire with Israeli soldiers on a mission to destroy infiltration tunnels.
Eight rockets and mortar bombs were fired from Gaza at Israel, the military said, adding that one was intercepted by the Iron Dome system and seven hit open areas.
An official in Israeli Prime Minister Benjamin Netanyahu's office said Hamas and other armed groups in the Gaza Strip had "flagrantly violated the ceasefire". But the official stopped short of formally declaring the truce over.
After the ceasefire began at 8 a.m. (0500 GMT), Gaza's streets began to fill with Palestinian families. Laden with belongings, they streamed back to homes they fled during fierce fighting that destroyed or damaged thousands of dwellings.
"We are going back to Beit Lahiya (in the northern Gaza Strip)," said Asharaf Zayed, a 38-year-old father of four. "We hope the truce will be permanent and we won't have to go back to a U.N. shelter."
Amid strong public support in Israel for the Gaza campaign, Netanyahu had faced intense pressure from abroad to stand his forces down.
International calls for an end to the bloodshed intensified after shelling on Wednesday that killed 15 people sheltering in a U.N.-run school in Gaza's Jabalya refugee camp.
The truce left Israeli ground forces in place in the Gaza Strip and a military spokeswoman said operations were continuing to destroy a warren of tunnels through which Hamas has menaced Israel's southern towns and army bases.
"We are doing what needs to be done in order to neutralise them," she said.
Accomplishing that mission - the military said on Thursday the tunnels hunt could be wrapped up in a few days - could open the way for Israel to declare it has achieved the main goal of the ground assault and withdraw its soldiers from Gaza.
"Our understanding is that the Israelis will make clear to the U.N. where their lines are, roughly, and they will continue to do operations to destroy tunnels that pose a threat to Israeli territory that lead from the Gaza strip into Israel proper as long as those tunnels exist on the Israel side of their lines," a U.S. State Department official said.
Hamas, isolated in an Arab world concerned about the rise Islamist militancy, is seeking an end to Israel's blockade of Gaza. It also wants a hostile Egypt to ease restrictions at its Rafah crossing with the territory imposed after the military toppled Islamist president Mohamed Mursi last July.
Israel has balked at freeing up Gaza's borders under any de-escalation deal unless Hamas's disarmament is also guaranteed.
A senior State Department official travelling with Kerry in India said U.S. Deputy Secretary of State Bill Burns would arrive in Cairo on Saturday and that Frank Lowenstein, the acting U.S envoy for Middle East peace, and another U.S. official, Jonathan Schwartz, would be there on Friday.
The official said he believed the Palestinians would be in Cairo on Friday, while the Israelis would arrive on Saturday.
The Palestinian delegation will be comprised of Hamas, Western-backed Fatah, the Islamic Jihad militant group and a number of smaller factions, Palestinian officials said.
But U.S. officials said Israel and the United States would not sit across the table from Hamas, which the two countries, along with the European Union, consider a terrorist group.
Just over an hour before the ceasefire was due to take effect militants fired 11 rockets into Israel, one of which was intercepted by the Iron Dome defence system over the centre of the country, a military spokeswoman said.
Israeli strikes killed 14 people in Gaza, including eight from one family, hospital officials said. Earlier, Hamas rockets set off sirens in the Tel Aviv area and one was intercepted.
Israel's military said five of its soldiers were killed late on Thursday by a mortar bomb.
Previous international attempts to broker a humanitarian truce secured only shorter periods of calm, with some collapsing immediately after being announced.
(Additional reporting by Ari Rabinovitch, David Brunnstrom in New Delhi; Lesley Wroughton in Washington; Michelle Nichols at the United Nations; and Omar Fahmy in Cairo; Writing by Jeffrey Heller in Jerusalem; Editing by Giles Elgood)
Our Standards: The Thomson Reuters Trust Principles.