In a Nov. 29, 2016 file photo, former North Charleston police officer Michael Slager testifies during his murder trial at the Charleston County court in Charleston, S.C. Slager was sentenced to 20 years in prison Thursday, Dec. 7, 2017, for 2015 fatal shooting of unarmed black motorist Walter Scott. (Grace Beahm/Post and Courier via AP, Pool, File)

A white former South Carolina officer was sentenced to 20 years in prison on Thursday for fatally shooting an unarmed black motorist in the back in 2015, wrapping up a case that became a rallying cry for the Black Lives Matter movement.

Attorneys for ex-North Charleston Officer Michael Slager said he shot 50-year-old Walter Scott in self-defense after the two fought and Scott grabbed Slager’s stun gun. They said race didn’t play a role in the shooting and Slager never had any “racial animus” toward minorities.

Still, Slager pleaded guilty in federal court to violating Scott’s civil rights. As part of the plea agreement reached in May, prosecutors dropped state murder charges. A year ago, a state judge declared a mistrial when jurors deadlocked in that case.

“This is a tragedy that shouldn’t have happened,” U.S. District Judge David Norton said.

A bystander recorded the shooting on a cellphone, and it was shared around the world, setting off protests across the U.S. as demonstrators said it was another egregious example of police officers mistreating African-Americans.

Slager fired at Scott’s back from 17 feet (5 meters) away. Five of eight bullets hit him.

The video was seized on by many as vivid proof of what they had been arguing for years: that white officers too often use deadly force unnecessarily against black people.

When the jury failed to reach a verdict in the state murder case, many black people and others were shocked and distressed, because the video seemed to some to be an open-and-shut case. Some despaired of ever seeing justice.

Scott’s family testified before the sentence was handed down and said they had forgiven Slager.

“I’m not angry at you, Michael. Michael, I forgive you, and Michael, I do pray for you now and for your family, because we’ve gone through a traumatic time,” said Scott’s brother Anthony.

The shooting angered local African-Americans who complained for years that North Charleston police harassed blacks, pulling them over or questioning them unnecessarily as they cracked down on crime. But after the shooting, the Scott family successfully pleaded for calm, asking everyone to let the justice system run its course.

Two months after the shooting, a young white man killed nine black church members in a racially motivated attacked during a Bible study in Charleston. The family members of those victims struck a similar forgiveness tone after that attack.

Before the sentence was handed down, the judge had to decide whether the shooting amounted to second-degree murder or manslaughter. Norton found that it was murder.

“No matter what sentence I give, neither the Scott family nor the Slager family is going to think that it’s right,” the judge said.

After the shooting, Slager picked up his stun gun and placed it next to Scott. Slager contends he was securing the weapon. Prosecutors think he put it there to bolster his self-defense story.

In this Monday, Dec. 5, 2016, file photo, Judy Scott, center, Walter Scott’s mother, is comforted by her son Rodney Scott, as the family attorneys, Chris Stewart, left, and Justin Bamberg, right, hold a press conference. (AP Photo/Mic Smith, File)

An emotional Slager told the Scott family that he was grateful for their forgiveness.

“This tragic event that occurred in seconds has changed the lives of everyone involved,” he said. “With my actions that day, Walter Scott is no longer with his family, and I am responsible for that.”

The judge also found that Slager, 36, obstructed justice when he made statements to state police after the shooting.

A pre-sentencing report for Slager found that he committed manslaughter and recommended 10 to nearly 13 years in prison. But the judge was not bound by that review.

If Slager had faced another state trial and been convicted of murder, he could have been sentenced to anywhere from 30 years to life in prison.

Convictions in police officer shootings are uncommon in the U.S. and prison time is even rarer.

South Carolina has been aggressive in charging white officers who shoot unarmed black people. Four have pleaded guilty in state or federal court in the past six years. But only Slager and former state trooper Sean Groubert, who shot a man as he tried to get his wallet during a seat belt violation check, will have been sent to prison. Groubert was sentenced to five years behind bars.