Navy Special Operations Chief Edward Gallagher and his wife, Andrea, as arrive Thursday at the military court on Naval Base San Diego. Gallagher has pleaded not guilty to charges of murder and attempted murder stemming from his 2017 tour of duty in Iraq. Julie Watson/Associated Press

SAN DIEGO — A witness called to testify against a decorated Navy SEAL charged with murder said Thursday that he killed the victim, a bombshell admission he described as an act of mercy for the wounded Islamic State fighter.

Special Operator 1st Class Corey Scott said he asphyxiated the adolescent prisoner in Iraq two years ago after Special Operations Chief Edward Gallagher unexpectedly stabbed him.

A visibly angry prosecutor accused Scott of lying, saying he had told investigators a different story over the months and changed it only after a judge granted him immunity and ordered him to testify.

The testimony is the latest setback for prosecutors and a big boost for Gallagher, who is fighting charges of premeditated murder in the boy’s death and attempted murder in the shooting of civilians.

Before the stabbing, Scott said that he and Gallagher had stabilized the sedated prisoner who was wounded in an airstrike and that he was breathing normally through a tube inserted to clear his airway.

Scott said he was shocked when Gallagher, the platoon’s leader, stabbed the boy at least once below the collarbone. He said there was no medical reason for it. Gallagher then grabbed his medical bag and walked away.

“I was startled and froze up for a little bit,” Scott said.

Scott said the boy would have survived the stabbing, but he plugged the youth’s breathing tube with his thumb because he believed the prisoner would eventually be tortured by the Iraqi forces who captured him and delivered him to the SEAL compound for medical treatment.

“I knew he was going to die anyway, and I wanted to save him from waking up to whatever would happen to him,” Scott said.

Scott was the fourth SEAL to take the stand and second to say he witnessed the stabbing. Prosecutors have alleged that the stabbing killed the boy.

The prosecutor, Lt. Brian John, accused Scott of lying, saying he had changed his story only after being granted immunity that prevents him from being charged in the killing.

“So you can stand up there and you can lie about how you killed the ISIS prisoner so Chief Gallagher does not have to go to jail,” John said. “You don’t want Chief Gallagher to go to jail, do you?”

“He’s got a wife and family,” Scott said. “I don’t think he should be spending his life in prison.”

Scott met repeatedly with investigators and never revealed he had anything to do with the death, John said. He had always asserted that there was no way to save the prisoner’s life.

Scott said no one asked him how the patient died and acknowledged the immunity deal allowed him to finally fess up.

He wanted to invoke his Fifth Amendment right against self-incrimination when called by the prosecution, but the judge rejected that. Capt. Aaron Rugh granted him immunity and ordered him to take the stand.

The testimony follows another serviceman who described the stabbing and a former SEAL who said Gallagher later scoffed that the victim was “just an ISIS dirtbag.”

The former SEAL, Dylan Dille, also described several instances when he said Gallagher had fired at civilians, once shooting an old man.

Scott said he did not recall previously telling investigators that Gallagher had shot women and children.

The defense has said Gallagher only treated the prisoner for a collapsed lung and that disgruntled sailors fabricated the murder accusations because he was a demanding leader and they didn’t want him promoted.

Gallagher’s case has drawn the attention of President Trump, who ordered him moved from the brig to a Navy hospital earlier this year and is reportedly considering a pardon.

The case has been mired with news leaks of investigative documents that are under court order only to be shared among lawyers.

The judge recently removed the lead prosecutor from the case over a bungled effort to track emails sent to defense lawyers in order to find the source of the leaks.

Rugh determined that the effort, which was quickly discovered by the defense, violated Gallagher’s constitutional rights against illegal searches and the right to counsel by interfering with attorney-client privilege.

He declined to dismiss the case but freed Gallagher, reduced the maximum possible punishment from life in prison without parole to the possibility of parole, and made it easier for the defense to get a more favorable jury.

The seven-man jury is made up of five Marines and two sailors – all veterans of war zones. A two-thirds majority – at least five – is needed to convict. Anything less ends in acquittal.