ST. PAUL — A Minnesota police officer, whose fatal shooting of a black motorist transfixed the nation when his girlfriend livestreamed the aftermath, was acquitted of all charges on Friday.

The officer, Jeronimo Yanez, had been charged with second-degree manslaughter and endangering safety by discharging a firearm in the shooting of Philando Castile.

After the verdict, jurors and Mr. Yanez were quickly led out of the courtroom, and Mr. Castile’s family left immediately. When a deputy tried to stop his mother, Valerie, she yelled “Let me go.”

Later, she said: “My son loved this city, and this city killed my son. And a murderer gets away. Are you kidding me right now?”

She continued: “The system in this country continues to fail black people and will continue to fail us.”

A handful of protesters gathered outside the Ramsey County courthouse. “It’s not us that were on trial, it was the system that was on trial,” Mel Reeves, a community activist, said. “Yanez worked for the system. He killed somebody, right. Philando Castile got victimized by the system.”

The verdict, which came on the fifth day of deliberations, followed the acquittal last month of an Oklahoma police officer who killed an unarmed black man and, of particular interest here, a prosecutor’s decision last year not to charge the Minneapolis officers who killed another black man, Jamar Clark.

Mr. Castile’s death on July 6, 2016, became international news almost immediately because his girlfriend, Diamond Reynolds, who was sitting in the front seat, streamed the aftermath live on Facebook.

From that moment, the case hinged largely on conflicting accounts of what Mr. Castile was doing before he was shot. Officer Yanez claimed in the Facebook video, and again last week on the witness stand, that he believed Mr. Castile was grabbing a gun. Ms. Reynolds said in the video, and testified in court, that Mr. Castile had been trying to cooperate and produce his driver’s license.

The killing led to weeks of protests here, including an encampment outside the Minnesota governor’s mansion, and renewed questions about how officers use force and treat black people.

Prosecutors said Officer Yanez had created a dangerous situation, perceived a threat where none existed and, in addition to killing Mr. Castile, almost wounded Ms. Reynolds and her young daughter in the back seat.

“He was making assumptions and jumping to conclusions without engaging in the dialogue he was trained to have in a citizen encounter like this,” Jeffrey Paulsen, a prosecutor, said in closing arguments on Monday. “And that’s his fault, not the fault of Philando Castile.”

Mr. Castile was licensed to carry a gun and was recorded on a dashboard camera video calmly telling Officer Yanez that he had a weapon in the car. Officer Yanez told him not to reach for the weapon, and Mr. Castile and Ms. Reynolds both tried to assure the officer that he was not doing so. Within seconds, Officer Yanez fired seven shots. Prosecutors said Mr. Castile had mentioned his gun to allay concerns, not to threaten the officer or escalate the situation.

“If someone were just about to reach in their pocket and pull out a gun and shoot an officer, that’s the last thing they would say,” Mr. Paulsen said.

Earl Gray, a lawyer for Officer Yanez, said his client had to react quickly to what he believed was an imminent threat. Mr. Gray said Officer Yanez smelled marijuana, believed Mr. Castile matched the description of a recent robbery suspect and saw him grabbing a gun.

Graphic | Few Police Officers Have Been Convicted in High-Profile Cases Involving Deaths of Blacks What happened in recent cases where blacks were killed by the police or died in police custody.

“We have him ignoring his commands. He’s got a gun. He might be the robber. He’s got marijuana in his car,” Mr. Gray told jurors. “Those are the things in Officer Yanez’s head.”

Officer Yanez did not tell Mr. Castile about the robbery suspicions, only that his brake light was out. But Mr. Gray said that this approach made sense, and that Officer Yanez had acted reasonably given his training and what he knew that night.

“He did what he had to do,” Mr. Gray said, adding that the situation was “tragic.”

The jury of 12, including two black people, had to sort through the competing narratives. Both prosecutors and defense lawyers said the video footage supported their version of events.

The case was extraordinary in Minnesota — it is believed to be the first time in the state’s history that an officer was charged in an on-duty fatal shooting — and was closely watched by police officers and protesters. On Monday, a passing motorist yelled “guilty!” at three jurors taking a smoke break, one of them told the judge.

The trial took place amid a national debate over whether officers can or should be convicted of crimes. In Tulsa, Okla., Officer Betty Jo Shelby was acquitted of manslaughter last month in the fatal shooting of an unarmed black man. Officers were also standing trial this week in fatal shootings in Cincinnati and Milwaukee.

At Officer Yanez’s trial, in a small courtroom in downtown St. Paul, defense lawyers made repeated mention of Mr. Castile’s and Ms. Reynolds’s use of marijuana. The drug was found in Mr. Castile’s car after the shooting, and Mr. Gray claimed that Mr. Castile had been under the influence of marijuana and delayed in his reactions at the time of the shooting.

“We’re not saying that Philando Castile was going to shoot Officer Yanez,” Mr. Gray said. “What we’re saying is that he did not follow orders. He was stoned.”

But Mr. Paulsen, the prosecutor, said that version of events was contradicted by video. He said footage showed that Mr. Castile was driving normally, pulled over quickly and was alert and courteous when talking to Officer Yanez. He accused the defense of blaming the victim.

“He offered no resistance,” Mr. Paulsen said of Mr. Castile. “He made no threats. He didn’t even complain about being stopped for such a minor offense.”

Correction: June 16, 2017

An earlier version of a picture caption with this article misspelled the given name of the officer who was acquitted. He is Jeronimo Yanez, not Geronimo.