Two police officers in Stroud barricaded themselves in a takeaway shop after youths became abusive.
About 20 youths were reported to police for swearing and threatening customers in the Subway Sandwich bar in Kings Street on Monday night.
Police arrested one youth for insulting behaviour in a public place.
The others then tried to stop the arrest and began smashing shop windows. Police waited inside the shop until the situation had calmed down.
The officers, with the help of staff, managed to lock the doors as the youths attempted to break in to the restaurant.
The policemen had been talking to one teenager inside the store, when a second youth started abusing the officers.
They escorted him into Subway and were in the process of arresting him, when a group of around 20 of his friends attempted to break into the shop to "save him".
The teenagers, who were aged between 14 and 17, ran off when the support units arrived.
Chief Superintendent Dean Walker, of Gloucestershire Police, said: "This was an exceptional event and not something we have had to contend with very often.
"I would like to take this opportunity to praise the officers involved for dealing with the incident in a thoroughly professional manner."