JERUSALEM — After days of violent protests, bloodshed and a diplomatic crisis with Jordan over the placement of metal detectors at the entrances to the Aqsa Compound in Jerusalem’s Old City, the Israeli government said early Tuesday it would remove them.

The decision came after a day of intense discussions between leaders of Israel and Jordan, the custodian of the shrine. It also occurred hours after the end of a standoff prompted by a confrontation at the Israeli Embassy in Amman, Jordan, that led to the deaths of two Jordanians. The standoff appeared to have eased late Monday, with the arrival of the embassy staff back in Israel.

The Israeli ambassador to Jordan, Einat Shlain, and her staff, including a security guard at the center of the fray, returned home soon after a telephone call between King Abdullah II of Jordan and Prime Minister Benjamin Netanyahu of Israel. The decision to remove the metal detectors was announced hours later.

The king discussed the Aqsa Mosque crisis, according to the official Jordanian news agency, Petra, and urged Mr. Netanyahu to remove “measures adopted by the Israeli side,” meaning the metal detectors. Jordan had taken a hard line from the start against the new security measures.

Lifting a nightlong news blackout on the embassy attack, Israel’s Foreign Ministry said Monday morning that a Jordanian worker who had come to help replace furniture stabbed the Israeli security guard with a screwdriver. The guard, who was not seriously wounded, “defended himself,” the ministry said, without saying how.

The Jordanian worker — Mohammed Jawawdah, 16 — was shot and killed, according to Jordan’s Public Security Directorate. The Jordanian landlord of the embassy’s residential quarters, a doctor who had accompanied Mohammed and another worker, was also hit and later died of his wounds.

Both sides were sparing with words. Petra described the event as a “shooting incident” and made no immediate mention of the stabbing.

Mohammed’s father, Zakaria Jawawdah, told Reuters, “My son was not a troublemaker or a terrorist, and he did not belong to any political parties.”

The episode quickly turned into a charged, if discreet, showdown over diplomatic immunity, with Jordan initially demanding to question the Israeli security guard and barring him from leaving the country.

Mr. Netanyahu dispatched the chief of the Shin Bet, Israel’s internal security agency, to Amman to handle the emerging crisis.

“I assured the security guard that we will see to bringing him back to Israel; we have experience in this,” Mr. Netanyahu said earlier. Israel’s Foreign Ministry said the security officer had immunity from investigation and imprisonment under the terms of the Vienna Convention.

“We’ve seen examples where drivers have even killed people by running them over and were not arrested, but were given the opportunity to leave the country,” said Zalman Shoval, a former ambassador to the United States from Mr. Netanyahu’s Likud Party.

After the diplomats arrived in Israel, Mr. Netanyahu’s office said in a statement, “The return of the embassy personnel was made possible thanks to the close cooperation that took place over the past 24 hours between Israel and Jordan.”

This latest round of diplomatic wrangling and bloodshed began with a brazen attack on the morning of July 14, when three armed Arab citizens of Israel emerged from Al Aqsa Mosque and fatally shot two Israeli Druze police officers who were guarding the compound. Mr. Netanyahu quickly ordered metal detectors and cameras placed at entrances to the holy site, which is revered by Jews as the Temple Mount and by Muslims as the Noble Sanctuary.

Palestinian Muslims have since refused to enter the esplanade, praying in protest outside.

Since the metal detectors went up, three members of an Israeli family were stabbed to death in an attack at their home in a West Bank settlement and four Palestinians were killed in clashes with security forces in and around Israeli-annexed East Jerusalem.

At the United Nations, the Israeli and Palestinian ambassadors traded barbs on Monday, as the Security Council met behind closed doors with the United Nations envoy in charge of the tattered Israeli-Palestinian peace process.

The Israeli ambassador, Danny Danon, accused the Palestinian Authority of rewarding the man who stabbed the Israeli family in the West Bank. “This attack is not an isolated incident. It is part of a wave of terror sweeping the free world by those brainwashed by hateful teachings,” he said.

The Palestinian ambassador, Riyad Mansour, retorted by pointing to Israeli occupation of Palestinian lands and violence carried out by Israeli settlers in the occupied West Bank.

Asked to comment on the stabbings, Mr. Mansour said the Palestinian authorities cannot be held responsible for the behavior of individuals who act out of frustration. “Don’t expect all Palestinians to be angels,” Mr. Mansour said. “Even some might take the issue in their hands as individuals.”

The metal detectors, in the meantime, have become a symbol of the broader struggle over ownership and control of the contested compound.

Israel captured East Jerusalem, along with its holy sites, from Jordan in the 1967 war, and annexed the area in a move that was never internationally recognized. Under the delicate arrangements that have governed the administration of the site for decades, Jordan maintains a special role, reaffirmed in its peace treaty with Israel in 1994.

Even before the deadly confrontation in the Israeli Embassy compound in Amman, the capital, Jordan — whose population includes many people with Palestinian roots — had called for an emergency meeting of Arab foreign ministers and had urged Israel to respect the historical status of the holy site, rescind unilateral moves and remove the metal detectors.

Israeli analysts said the two countries would have to find a solution that would not be seen as rewarding violence, from Israel’s perspective, but placate the angry Jordanian public.

“The basic interest of both countries is to have this resolved effectively,” said Eran Lerman, a former deputy director of Israel’s National Security Council, in a conference call with reporters. “I’m not sure there’s a simple way out now that does not look like retreat in the face of violence and terror.”