ROME — Italy closed its consulate in Benghazi, Libya, and withdrew its staff because of security concerns, after an attempted ambush of the Italian consul over the weekend.

Though the diplomat, Guido De Sanctis, escaped unharmed, the episode raised concerns about the tenuous security situation in Libya as the transitional government struggles to rebuild the country after the overthrow of Col. Muammar el-Qaddafi nearly two years ago.

The Italian Foreign Ministry said the attack was an attempt to disrupt the Libyan government’s efforts, “further proof of the international community’s need to intensify support for the Libyan people and institutions.”

In the ambush on Saturday, gunmen fired on Mr. De Sanctis as he drove through Benghazi, but none of the bullets penetrated his vehicle, an armored model that was issued to him after the Sept. 11 assault on the American mission in Benghazi, in which Ambassador J. Christopher Stevens and three other Americans were killed.