A group of teenagers in western New York has been accused of harassing members of a mosque by yelling obscenities and insults during evening prayers for Ramadan, sideswiping a worshiper with a vehicle and firing a shotgun outside, the authorities said Tuesday.

The teenagers were cornered by members of the mosque, who held them for the police. They were charged with disrupting a religious service, a misdemeanor.

The obscenities episode occurred Monday and the shooting last Friday, both outside the World Sufi Foundation mosque in Carlton, N.Y., the authorities said. They said a 17-year-old fired the shotgun; no one was hit.

“We have had occasions in the past,” said Joseph V. Cardone, the district attorney in Orleans County, “and it seems every three or four years we have some kids drive by the mosque and make comments and that sort of thing. We’ve had minor incidents, but nothing of this magnitude in the past.”