Madrid Security Commissioner José Javier Barbero and the municipal police chief Andrés Serrano were chased into hiding in a bar as a hoard of protesting police hurled insults and attacked their car.
The officers were protesting the city's decision to dissolve one of the units of the Central Security Units (UCS), known as "anti-riot squads".
The elimination of the unit is part of a city hall plan under left-wing mayor Manuela Carmena to have police focus more on providing services to citizens, rather than on controlling them.
The plan also bans anti-riot cops from monitoring protests and evictions.
The protest by police union CPPM began on Tuesday morning around Plaza Mayor. When the two security officials left a meeting in a nearby municipal building, the protesters started following them while booing, whistling and calling out insults like "fatso," "fascist," "dictator" and "son of a bitch", saying they should resign.
Barbero and Serrano at first looked for their official car to get away from jeering, but decided to escape into a bar when they found the car had not yet arrived. El Pais noted that the two had help to eventually leave the bar from the Unit of Police Intervention, an anti-riot unit with the national police.
Barbero later said at a press conference that he will investigate whether the insults may be considered a crime of incitement of hatred. He also criticized the National Police for not intervening, according to broadcaster RTVE.