Israel and militants based in the Gaza Strip agreed to a truce Tuesday, ending a four-day cross-border battle whose intensity and resolution highlighted shifting regional dynamics.

The cease-fire was brokered by Egypt, which has served as a negotiator between Israelis and Palestinian militants in the past. Though the terms of the truce remained unclear, it halted Israeli airstrikes on Monday night, and by Tuesday afternoon what had been a constant barrage of rocket fire from Gaza into southern Israel had slowed dramatically.

Both Israel and Hamas, the Islamist militant movement that rules Gaza but did not participate directly in the fighting, had seemed disinclined to let the clashes trigger all-out war.

Egypt continues to play a central role in Israeli-Palestinian relations even as it undergoes its own turbulent transition following the ouster of President Hosni Mubarak and the ascendance of Islamist parties. Analysts said both Israel and Hamas are seeking to buoy relations with Egypt — Hamas because it senses opportunity in the rise of Egypt’s Muslim Brotherhood, and Israel because it wants to maintain its long-standing but shaky peace treaty with Cairo.

“The national security interest of Egypt is always in our calculations,” Amos Gilad, a senior Israeli defense official, told reporters in a conference call.

At the same time, the truce was delayed because the main militant faction behind the rocket firing, Islamic Jihad, is positioning itself as a rival to Hamas in Gaza. As the conflict escalated, Islamic Jihad suggested that Hamas was failing to defend the coastal enclave.

“It took the Egyptians longer to broker a cease-fire. . . . The Islamic Jihad did not want to abide,” said Mkhaimar Abusada, a political science professor at Al-Azhar University in Gaza. Hamas, he said, “is aware that any major military operation by Israel will be devastating to the Palestinian people, as well as Hamas.”

The clashes began Friday, after an Israeli airstrike killed the top commander and another member of the Popular Resistance Committees, a militant faction that the Israeli military said was plotting an attack on southern Israel via Egypt’s Sinai Peninsula. The poorly policed region is of growing concern to Israel. Gilad, the defense official, called on Egypt to “do the work” to control the Sinai, and he accused Palestinian militants of “trying to complicate our relations with Egypt.”

Militants in the coastal strip responded to the two killings with rocket fire, which Israel sought to quash with airstrikes on what it said were rocket-launching squads and weapons factories. The rockets caused no Israeli fatalities, but it suspended life in the country’s south.

At least two dozen Palestinians were killed in the airstrikes. Medics in Gaza said that most were militants but that at least four were civilians.

On Tuesday, Islamic Jihad and the Popular Resistance Committees said they would stick to the truce if Israel stopped targeted assassinations of militant leaders, which they said Israel had agreed to. Israeli officials denied that.

“Our message is clear: Quiet will bring quiet,” Israeli Prime Minister Benjamin Netanyahu said of the truce Tuesday. “Whoever violates it or even tries to violate it — we will find him.”

The conflict gave Israel, which is mulling a strike on Iranian nuclear facilities, the opportunity to demonstrate its year-old Iron Dome antimissile system. Currently deployed only in Israel’s south, the system intercepted dozens of rockets that targeted population centers, and Israeli officials lauded its performance.

Special correspondent Islam Abdulkarim in Gaza contributed to this report.