A man shot by Long Beach police in October was wanted for trying to kill a witness he hoped to stop from testifying in a gang murder, detectives allege in court records.

Long Beach police recently released details about how a detective shot and wounded 33-year-old Oscar Alejandro Ramires when Ramires allegedly rammed his car into the detective’s vehicle in an attempt to escape capture. But the department has said very little publicly about why they were tracking Ramires and what led up to the Oct. 31 confrontation at a Montebello gas station.

Court documents, including a detailed search warrant obtained by the Long Beach Post, show Ramires was wanted in a string of crimes, chief among them the attempted murder of a woman whom his gang believed had turned on them and was preparing to testify against one of its members.

To avoid identifying her, the Long Beach Post is not naming the woman or detailing the incident police said she witnessed. She is currently in protective custody, according to court records.

The documents detailing the LBPD’s investigation into Ramires show the woman he’s accused of trying to kill was originally arrested as a suspect in the gang murder investigation, but when she spoke to prosecutors and gave a statement against one of her co-defendants, the charges against her were dropped, and she was slated to become a witness in the case.

This did not sit well with Ramires’ gang, police allege.

“Homicide detectives believe the North Side Longo gang was targeting her for violence to prevent her from testifying,” they wrote in the search warrant. “This is based on multiple recorded jail calls, prison calls, and social media posts.”

Around the time of a pivotal court hearing, Ramires pistol-whipped the woman and warned her against testifying, according to detectives’ account. When she failed to appear in court, a judge authorized her arrest, police wrote.

Ramires kept the pressure on, according to the records, showing up at her home and demanding to see her.

“This Longo. Tell [her] to stay off the north,” the warrant recounts one witness saying, presumably warning her away from gang territory.

When the woman came outside, Ramires fired at least four shots at her, according to the warrant.

By the time officers arrived, all that was left were bullet casings and blood droplets outside an apartment complex, according to the warrant. When they found the woman at a local hospital, she was reluctant to talk, police wrote.

Ramires, meanwhile, continued his intimidation campaign, police allege. They say he reposted what appeared to be a bounty on Facebook.

“The bounty featured (the victim’s) photograph, address and phone number. The price on her head was listed as $5,000,” police wrote in the warrant.

During this time, police also identified Ramires as a suspect in two unrelated car-to-car shootings in October, according to the warrant.

This all culminated on Oct. 31, police wrote, when Ramires, who was at his home in Montebello, drove to a nearby gas station and got out of his car.

That’s when he noticed a marked LBPD squad car and got back into his car, according to police’s description of events and surveillance footage they released.

As the officers box him and order him to get out of the car, Ramires begins to crash into nearby cars looking for a way to escape.

With seemingly no exit, Ramires rams his vehicle into a detective’s car, prompting the detective to fire two rounds at him, police say.

At least one of the rounds strikes Ramires, who drives away, crashing into more vehicles in the gas station lot as he makes his way onto the road, according to police.

A wounded Ramires continued driving for less than a quarter of a mile before crashing at a nearby intersection and running away, the LBPD said.

Police still close behind, Ramires is accused of then running into an apartment complex garage where officers found him face down and took him into custody before he was rushed to the hospital.

Ramires has since been charged by the Los Angeles District Attorney’s office with attempted murder, assault with a semi-automatic firearm, dissuading a witness by force or fear, assault with a deadly weapon and assault upon a peace officer.

Court records show Ramires pleaded not guilty to the charges during his arraignment on Nov. 2. His attorney declined to comment Tuesday.

Ramires is due back in court Dec. 19 for a hearing. Meanwhile, he remains jailed in lieu of $2.27 million bail, inmate records show.