Prosecutors have decided Long Beach police were justified in the controversial deadly shooting of a man they said lunged at them with a knife despite a police dog biting his arm and an officer firing rubber rounds at him.

A Long Beach SWAT officer fatally shot Barry Prak, 27, in the chest after a standoff in central Long Beach on June 28, 2016. His death sparked a march for justice and a petition against police brutality.

At least 100 people attended a vigil for Prak, who’d protested against the Long Beach Police Department in the past.

But investigators concluded that the officer who pulled the trigger, Patrick Dougherty, acted in self-defense, according to a letter from the Los Angeles County District Attorney’s office released Tuesday afternoon.

A Long Beach police dog named Credo was also killed by friendly fire in the shooting, according to authorities.

The letter provides the most detailed picture yet about how Prak was killed. It includes screenshots from a video of the shooting.

“A neighbor recorded the incident with her cell phone, which corroborates both law enforcement and civilian accounts of what happened,” the letter states.

On June 28, authorities came into contact with Prak around 9 a.m. when a U.S. Marshal Fugitive Task Force tried to arrest him on an outstanding warrant related to a 2014 gang shooting in Cambodia Town that wounded three men, according to the letter.

Officers approached Prak on a sidewalk, but he ran — successfully avoiding a Taser — until he got to a friend’s apartment a few blocks away and barricaded himself inside, investigators wrote.

About 30 minutes later, a Long Beach police SWAT team arrived at the apartment in the 2800 block of E 15th Street.

Two other people inside the apartment came out peacefully and told officers there were no guns inside, but Prak did have access to knives, according to the letter.

From inside, Prak would occasionally yell to police, according to the district attorney’s office.

At one point, he yelled a profanity and said, “I hope you guys all die,” the letter states.

“Another time he said that he wanted the media present when he surrendered,” investigators wrote. “He also announced that he would exit in ‘ten minutes’ shortly before he exited the apartment.”

At about 11 a.m., Prak came outside, according to authorities.

The letter highlights that he was now wearing a “baggy long-sleeved sweatshirt” instead of the T-shirt he’d been wearing when he ran inside the apartment.

According to the district attorney’s office, Prak followed some of the SWAT team’s commands and began walking toward them, but he refused to follow other directions and only kept his hands raised partially in the air.

When Prak was about 20 to 25 feet away from the officers, he complied with an order to crawl toward them on his hands and knees, according to investigators.

“As he got closer to the SWAT team, he was given several orders to get on his stomach,” the letter states. “Prak suddenly took his hands off the ground, stood up, and lunged toward officers as he manipulated an object in the sleeve of his sweatshirt.”

At that point, police released the dog, Credo, who bit Prak, and an officer fired four 40mm rubber rounds at him, according to the letter.

“Unfazed by both Credo and the less lethal rounds, Prak continued his forward movement toward the SWAT team,” the letter states.

In the span of about three seconds, Prak was within five feet of the officers and swinging the knife when Dougherty fired his rifle five times at Prak’s chest, according to the letter.

One of the rounds also hit Credo, killing him.

Authorities said police found Prak’s knife under his body.

“Prak’s actions prior to exiting the apartment show that he planned and prepared to use force against the officers under the guise of a surrender,” investigators said in the letter.

Prak was a member of the Asian Boys gang and considered possibly armed and dangerous based on the warrant out for his arrest, according to authorities.

According to his friends, Prak protested against Long Beach police after they shot and wounded a friend of Prak’s named Sokha Hor in January 2013. Police said Hor brandished a gun before he was shot.

Activists rallied when Hor’s family said they weren’t allowed to see him in the hospital for 10 days. Police eventually made arrangements for the family to visit.