FERGUSON, Mo. — A 20-year-old suspect was charged Sunday with shooting two police officers during a protest outside Police Headquarters here Thursday. Law enforcement officials said the man, Jeffrey L. Williams, claimed to have been targeting someone other than the officers and shot them by accident from inside a car.

Mr. Williams was arrested late Saturday and charged with first-degree assault in connection with the shooting, which had ratcheted up tensions between the police and protesters here. With the gunman at large, the officers guarding the police station as demonstrations continued had concerns for their safety, while protesters had criticized police officials for suggesting that the shooting was linked to them.

Discord has been simmering since Aug. 9, when a white police officer, Darren Wilson, fatally shot an unarmed, 18-year-old black man, Michael Brown, in a confrontation in the middle of a street. A grand jury declined to indict Mr. Wilson in November.