A 20-year-old man has been charged with first-degree assault for last week's shooting of two police officers during a protest in Ferguson, Missouri.
Jeffrey Williams admitted to firing the shots St Louis County Prosecuting Attorney Robert McCulloch told a news conference.
"It was not certain if he had been targeting police," he added.
The St Louis suburb has seen ongoing protests since a white police officer killed unarmed black teenager Michael Brown last August.
Mr Brown's death sparked demonstrations around the country and led to a US Justice Department inquiry.
Mr Williams, an African-American who had been on probation for possession of stolen property, was arrested after a massive manhunt.
Tips from the public and video evidence helped in the investigation, Mr McCulloch said.
"He has acknowledged his participation in firing the shots," Mr McCulloch said, adding Mr Williams had been at protests in the city.
Mr Williams, whose bond was set at $300,000 appears to have used a .40 calibre handgun and was firing from a car, Mr McCulloch said, adding it is possible he was shooting at someone else.
A handgun was recovered in his residence and matched shell casings found at the scene, according to Mr McCulloch, who said although Mr Williams appears to be the only shooter, other people may be charged as the investigation continues.
A 41-year-old county police officer suffered a shoulder wound and a 32-year-old colleague from a nearby police department sustained a facial wound that left a bullet lodged near his ear in last week's shooting.
Both were treated and released by a local hospital.
President Barack Obama condemned the attack.
The shootings took place just hours after Ferguson's police chief resigned in the wake of a scathing US Justice Department report finding his force was rife with racial bias.
Chief Tom Jackson's resignation followed the departures of the city manager, a municipal judge and two police officers.
The report said the St Louis suburb overwhelmingly arrested and issued traffic citations to African-Americans to boost city coffers through fines, used police as a collection agency and created a culture of distrust.