Antonio Simoes-Concalves, an Italian consular official, said nine protesters had been killed and several more had been wounded as armed police clashed with a crowd of more than 1000 demonstrators late on Friday.
Libyan state television showed a part of the consulate building on fire, and firefighters trying to extinguish it. The Italian Foreign Ministry confirmed that the first floor of the building had been set on fire after the crowd charged into the grounds of the consulate.
In a statement in Rome, the ministry said the consulate was being protected by Libyan security forces.
Libyan television also showed ambulances taking casualties away from the scene and five cars that were severely damaged in the riot.
Security officials said the demonstrators hurled stones and bottles at the consulate, and later entered the grounds and set fire to the building and a consular car.
Police fired shots to try to disperse the crowd, the officials said, speaking on condition of anonymity as they were not authorised to speak to the press.
Simoes-Goncalves told reporters in Rome that the Libyan police were not able to control the crowd, even though they were firing bullets and tear gas.
"They are still continually firing," he said speaking on the telephone from inside the consulate where he was holed up. "They haven't managed to block them."
He said the rioters had torched four cars in the consulate compound and also broke windows of the building. No Italians inside the compound were injured, the Italian Foreign Ministry said.