Image copyright Getty Images Image caption Protests erupted for days after officer Jason Stockley was acquitted in 2017 after killing motorist Anthony Lamar Smith in 2011

A US federal jury has charged three Missouri police officers with attacking a black officer working undercover whom they mistook for a protester.

After texting about how they wanted to rough up protesters, they brutally beat their police colleague with a riot baton, Thursday's indictment says.

It happened during protests in St Louis in 2017 after a white officer who killed a young black man was acquitted.

A fourth officer has also been charged for helping cover-up the incident.

The undercover officer has been named in court only as LH, but he was identified by the St Louis Post-Dispatch as Luther Hall, a city police officer with 22 years of service.

He was beaten so badly that he eventually needed surgery to his neck and spine and could not eat for days because of the injuries to his face, including a 2cm hole above his lip, the Post-Dispatch reported.

The three officers - 35-year-old Dustin Boone, 27-year-old Christopher Myers and 31-year-old Randy Hays - face charges including deprivation of constitutional rights, destruction of evidence and obstruction of justice and could be sentenced to up to 20 years in prison.

The fourth accused officer, 25-year-old Bailey Colletta, faces charges of lying to investigators.

Prosecuting US Attorney Jeff Jensen said in a statement: "These are serious charges and the vigorous enforcement of civil rights is essential to maintaining public trust in law enforcement."

What happened?

The three police officers exchanged text messages discussing attacking protesters, the indictment said.

"It's gonna be a lot of fun beating the hell out of these [expletive] once the sun goes down and nobody can tell us apart!!!!" one text from Mr Boone read.

"Remember were are [sic] in south city. They support us but also cameras. So make sure you have an old white dude as a witness," read another from Mr Hays.

Mr Boone, Mr Hays and Mr Myers allegedly threw the undercover officer to the ground, kicked him and beat him despite the fact he was "compliant and not posing a physical threat to anyone", the indictment said.

They later allegedly tried to cover up the incident by seeking to influence witnesses and contacting Mr Hall directly to dissuade him from pressing charges.

Ms Colletta, who was in a romantic relationship with Mr Hays, lied about knowing the victim and knowing about the attack, the indictment says. Mr Myers is also accused of intentionally destroying Mr Hall's cellphone.

The four have been suspended without pay.

Police Chief John Hayden said in a statement that he was "deeply disappointed" in the accused officers.

The 2017 protests came after police officer Jason Stockley was acquitted after killing 24-year-old Anthony Lamar Smith in 2011.

Some activists have now questioned whether Thursday's charges would have proceeded if the victim were not an undercover officer.

"We've had several incidents of protesters and activists being the victims of excessive use of force and police abusing their authority without ever seeing charges like this," local organiser Rev Darryl Gray told the Washington Post.