(Reuters) - A Minnesota police officer was charged with second-degree manslaughter on Wednesday for the fatal shooting of a black motorist that sparked outrage when the moments that followed were broadcast on social media.

St. Anthony police officer Jeronimo Yanez broke the law when he shot and killed Philando Castile in Falcon Heights, a St. Paul suburb, during a traffic stop, Ramsey County Attorney John Choi said.

Yanez’s attorney could not be reached for comment but Dennis Flaherty, head of the Minnesota police union, said the police community was disappointed and expected Yanez to plead not guilty.

Choi said Yanez feared Castile was reaching for a gun he had just calmly said he had in his possession, moments before being shot seven times by the officer.

A moaning Castile’s final words after being shot were, “I wasn’t reaching for it,” according to Choi, who said the conversation was picked up by a microphone Yanez was wearing.

Starting about 40 seconds after the shooting, Castile’s girlfriend, Diamond Reynolds, who was sitting in the vehicle’s passenger seat, streamed images of a bloody Castile on Facebook live, and the recording went viral on social media.

The incident began shortly after 9 p.m. local time on July 6, when Yanez pulled Castile over on suspicion of involvement of a robbery, Choi said. Castile had no involvement in the robbery, he added.

Diamond Reynolds, girlfriend of Philando Castile, weeps as people gather to protest the fatal shooting of Castile by Minneapolis area police during a traffic stop on Wednesday, in St. Paul, Minnesota, U.S., July 7, 2016. REUTERS/Adam Bettcher/File Photo

Castile, in a non-threatening manner, told the officer about the firearm he was carrying, Choi said.

Yanez interrupted and replied, “OK,” placed his hand on his gun, and then said, “OK, don’t reach for it then.”

Castile tried to respond but was interrupted by Yanez, who said, “Don’t pull it out.” Castile and Reynolds both responded he was not.

Yanez then screamed, “Don’t pull it out,” drew his own gun, and fired.

Another officer standing on the car’s passenger side said he did not see Castile make any sudden movements and was surprised by the shots, Choi said.

When officers and paramedics were moving Castile, they found a 40-caliber semiautomatic handgun in his right front pocket that had a loaded magazine but no round in chamber.

At the hospital, Castile’s wallet contained a driver’s license and his permit to carry a pistol.

“I cannot allow the death of a motorist who was lawfully carrying a firearm under these facts and circumstances to go unaccounted for,” Choi said.

Before Yanez, no officer had been charged in more than 150 police-involved deaths in Minnesota since 2000, according to the Star Tribune newspaper.

If convicted of the manslaughter charge, Yanez could serve almost 5 years in prison.

Yanez was also charged with two felony counts of dangerous discharge of a firearm that endangered the safety of Reynolds and her four-year-old daughter, who was also in the car.

Asked why he did not charge Yanez with more serious offense, Choi said this was the “highest, most provable offense.”

Choi said he met with Castile’s family on Tuesday night and informed them of the charges.

“The family is pleased with that recommendation because we know what type of charges could be brought about by the statutes of Minnesota laws,” Castile’s mother, Valerie Castile, told reporters. “We’re here in solidarity, my family and I, to support that decision.”

She also called for peace as the legal process continues.

Castile was remembered as a gentle man who was so smart he was considered over-qualified for his cafeteria supervisor job at a Minnesota public school, where kids loved him, according to friends, family and others.

Because the case is ongoing, Choi said he would not release the police car’s video and audio.

Yanez will make his first appearance in criminal court on Friday.