JERUSALEM – Israel apologized to Egypt on Saturday for the deaths of three Egyptian soldiers during a cross-border clash with Palestinian militants, hours after Cairo threatened to withdraw its ambassador to protest the killings.

Israel said the militants, who attacked Thursday, came from the Gaza Strip and went through Egypt’s Sinai desert, which borders both Israel and Gaza. They then crossed into southern Israel, where they ambushed and killed eight Israelis. There are conflicting reports of how the Egyptian soldiers were killed later that day, as Israel was pursuing militants along the border with Sinai.

“Israel deeply regrets the deaths of the Egyptian officers,” Defense Minister Ehud Barak said in a statement after Egypt threatened to recall its ambassador.

The Egyptian government initially put an announcement on its website overnight saying it had pulled the envoy, but later backtracked and issued a new statement saying it was only considering the move.

Late Saturday, Palestinians in Gaza unleashed a barrage of about 70 rockets at southern Israel, the military said, killing one Israeli and wounding dozens. The huge salvo threatened to escalate the already tense situation between Israel and Gaza militants into a full-blown conflict.

The violence is testing Israel’s landmark 1979 peace treaty with Egypt, already strained by the fall of longtime autocratic leader Hosni Mubarak.

The attacks have also raised concerns about the increasingly lawless northern Sinai, whose porous borders with both Israel and the Hamas-ruled Gaza Strip make it an attractive staging ground for Palestinian militant attacks on Israel.

The fall of Mubarak in a popular uprising in February has given way to a chaotic transition, with many in the discredited police force disappearing from the streets and leaving a tremendous security vacuum throughout the country, including Sinai.

Egypt recently moved thousands of troops into the Sinai Peninsula as part of a major operation against al-Qaida-inspired militants who have been increasingly active since Mubarak’s ouster.

At the same time, anti-Israel sentiment is up in Egypt and Israel is watching closely for signs that the military rulers who took power might be responding to that sentiment.

The ambush has also threatened to stoke the Mideast conflict as retaliatory violence between Israel and Gaza militants spiked. Israeli airstrikes killed at least 12 Palestinians, most of them militants, Friday in Gaza. Palestinians have fired about 120 rockets into southern Israel since Thursday, wounding more than a dozen people, including three Palestinians illegally residing there.

Israel said the clashes Thursday began when militants who crossed from Sinai, armed with guns, explosives, mortars and an anti-tank missile, launched a series of attacks on cars and buses.

Israel accused a Hamas-allied group, the Popular Resistance Committees, of carrying out the ambush. Hamas praised the attack — the deadliest on Israel since 2008 — but denied involvement.

There have been differing accounts of how the Egyptian soldiers were killed. Egypt says it was an Israeli airstrike along the Sinai border in response to the attacks.

Israel has offered conflicting accounts. One said there was an exchange of fire between its soldiers as they pursued the militants along the border. A senior Israeli military officer said it was possible that Egyptian soldiers had been killed accidentally.