Israel and militant groups in the Gaza Strip have agreed to a truce to end four days of violence in which 25 Palestinians were killed, a senior Egyptian security official has said.

Both sides have reached a deal to end operations, with Israel agreeing to "stop assassinations", and an overall deal to "begin a comprehensive and mutual [period] of calm", Reuters quoted the official saying.

Hamas and the Islamic Jihad faction confirmed the ceasefire.

"We accept a ceasefire if Israel agrees to apply it by ending its aggressions and assassinations," said Daud Shehab, spokesman for the Islamic Jihad movement.

"There is an understanding and we are following what's going on in the field," Israeli minister Matan Vilnai told Israel Radio.

The violence erupted on Friday, when Israel targeted a top militant leader. Zuhir al-Qaisi, leader of the Popular Resistance Committee, was driving through northern Gaza when rockets hit his car, killing him and his driver. An Israel Defence Force (IDF) spokesman said al-Qaisi was planning a coordinated terror attack on Israel's border with Gaza. Two mortar bombs were fired into Israeli territory. IDF officials said the initial attack was "unprovoked".

Israeli airstrikes killed two Palestinians and a schoolboy. Islamic Jihad said the two Palestinians were members of their group. Hospital sources said 25 civilians were wounded during the incident.

The Israeli military said the air force targeted Gaza in response to more than 20 rocket attacks.

Some feared the latest flare-up of violence in the Gaza Strip would trigger a bloody escalation similar to three years ago, when Israel's ground assault led to the deaths of 1,400 Palestinians and 13 Israelis.

The truce agreement followed appeals within and outside the Gaza Strip to exercise restraint.

Nader, a 24-year-old Gazan computer programmer and blogger, wrote a letter dedicated to "unborn children" in the strip. The blog post is going viral on Twitter with the hashtag #tomyunbornchildren.

In the letter, Nader depicts the daily challenge of living in Gaza, between the terror of being targeted by Israeli missiles and the dream of a peaceful and better life.

"In Gaza, everything is different," he writes. "In Gaza, Israeli F16s substitute birds. In Gaza, we sleep on the continuous buzzing coming from the ever-existent drones. We wake up to find that there's no electricity. In Gaza, explosions are the sunshine and the smell of ash is the scent of the city."

He accuses Israel's air forces of being unwilling to distinguish between military and civilian targets. "Meaning, they kill anything that moves with a smile," Nader writes. "Frankly, they would kill us more than once if possible."

The blogger concludes with a passionate appeal not to leave Palestine "It's where you belong," Nader explains. "It's where everything counts and where whatever little will make a huge change. Don't leave Palestine because it's my motherland. Your motherland."