The Italian officers were in Gaza to prepare for an upcoming visit by the Italian consul general based in Jerusalem, and were reportedly stuck in the UN building for around a day after the incident, according a diplomatic source.
They were allowed to leave after their identities were confirmed and it was determined they were not involved in any wrongdoing, a Gazan security source said.
Hamas has been on high alert for infiltrations following a botched Israeli special forces operation inside Gaza in November.
The unusual incident happened on Monday night, when the three officers were in a car in central Gaza as gunfire rang out, said Gaza interior ministry spokesman Iyad al-Bozum.
“The car then headed to a United Nations headquarters in Gaza City,” he said in a statement, adding that there were suspicions about their identities.
Hamas security forces pursued them and surrounded the building, leading to a standoff.
Hamas-affiliated media reported that the Italians had refused to be searched and then fled to the UN building, but al-Bozum did not comment on this.
The Gaza security source said that they had identified the three, clarified that their entrance to Gaza was legal and “that their car had no relation with the shooting incident.”
The diplomatic source said the discussions with Hamas were held through intermediaries, since Italy does not have contacts with the Islamist group, which the European Union labels a terrorist organisation.
The security agents left the Gaza Strip this afternoon, the source said.
Following the ill-fated raid in November, an Israeli undercover unit was discovered, leading to a gunfight in which seven Palestinians and one Israeli were killed.
The agents involved in the November raid were allegedly using fake ID documents and posing as charity workers.