RIO DE JANEIRO — Muggings, armed robberies and confrontations during Carnival celebrations in Rio de Janeiro are underscoring the deteriorating security situation in the city.

The television network TV Globo on Wednesday showed video of gunfire between rival drug gangs, teenagers punching tourists in areas usually considered relatively safe and a police officer narrowly escaping after several people attacked him in front of his home.

Gov. Luiz Fernando Pezão of the state of Rio acknowledged there were not enough police officers on hand during the first couple days of Carnival, though more than 17,000 officers worked in Rio State each day during the festivities.

“We were not prepared,” Mr. Pezão said. “There was a failure on the first two days, and then we brought backup for police. I think there has been a mistake in our part.”