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 Mosque Compound in Jerusalem’s Old City, the Israeli government said early Tuesday it would remove them.

The turnabout came after a day of intense discussions between leaders of Israel and Jordan, the custodian of the shrine, and with American mediation. 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 first indication of a deal came on Monday night, with the arrival of the embassy staff back in Israel. The Israeli ambassador to Jordan, Einat Shlain, and the 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.

Israel said the guard had opened fire in self-defense after being stabbed and had diplomatic immunity. Jordan had wanted to question him and initially barred him from leaving the country.