OAKLAND — Charles K. Goetting had four minutes when he was being questioned by BART police, a body in the back of his U-Haul truck, to decide what to do next.

Goetting, 32, chose to shoot at the BART officers, hitting one in the arm on Dec. 25, 2015, when it was clear they were going to search his truck, said Alameda County Deputy District Attorney Luis Marin during closing arguments Wednesday in the murder and attempted murder case.

The prosecutor said Goetting fired at the officers because he was “on his way to burying a body” — of his friend Jason Colin Anderson, 40, whom he had shot in the back of the head. Anderson’s body was wrapped in a tarp in the back of the truck.

Goetting’s defense attorney, Sydney Levin, doesn’t dispute that he fatally shot Anderson, but said that it was in self-defense. Two days after the shooting, on Christmas Day 2015 at the Hayward BART station, he opened fire on the officers because they weren’t going to believe his story that Anderson attacked him first with what looked like a real gun, she said.

“He was terrified. He was manic, he wasn’t thinking clearly,” Levin said. He also hadn’t slept in 48 hours, and had methamphetamine in his system, which increased his “impulsivity,” she said.

When he shot at BART Officer Carlos Dazhan and Officer Timothy Eads, who was hit in the arm, Goetting didn’t intend to kill, she said. He was in a panicked state, driving around the Bay Area with Anderson’s body in the truck. He was stranded at the BART station when the truck ran out of gas.

Price & Product Availability Tracker

Discover where products are available & compare prices

After Goetting opened fire, Dazhan tackled him and shot him four to five times; Goetting was then arrested.

Goetting and Anderson had gotten into a scuffle days before, and Anderson was the first to pull out what looked like a gun on Goetting, Levin said. They were both addicted to drugs and had run out when an argument arose. The defense maintained that Anderson accused Goetting of holding out on him, then attacked him with a gun.

Levin said Goetting knew of Anderson’s allegedly troubled past — his teardrop tattoo indicated he had killed someone before — and feared for his life. When the two struggled in the scuffle, he shot at Anderson, killing him.

But the prosecution alleges Goetting was in a different mindset — to get away with murder.

“On Dec. 25, 2015, the defendant had one goal, to get away with the murder of Jason Anderson. It didn’t matter what obstacle got in his way. He was willing to do anything and everything to remain a free man. If that meant taking the life of Officer Eads, so be it,” Marin said.

Marin argued that the attempted murder of Eads was premeditated: Goetting had those four minutes while interacting with the police to think about his move. He carefully weighed his choices: Get searched and have police find the body and go to jail, or become a free man by killing the officer, Marin said.

In the U-Haul, police found not only Anderson’s body, but also a pickax, a shovel and gas cans — tools to bury a body, the prosecutor said. It’s this information that proves the charge of first-degree murder, Marin argued.

“This is not how someone reacts when they accidentally kill someone,” Marin said.  With the dead body decomposing in the back of the truck, Goetting was “ready to bury that body with that shovel.”

When Goetting shot Anderson in the back of the head, Marin argued it “was not a warning shot, this was a kill shot.”

The jury was expected to begin deliberations late Wednesday afternoon after further instructions by the judge.

Staff writer Nate Gartrell contributed to this story.