SAN DIEGO -- When prosecutors called a special forces medic to testify, they expected him to bolster their case against a decorated Navy SEAL accused of stabbing an Islamic State fighter in his care.

Corey Scott delivered in part, saying Special Operations Chief Edward Gallagher unexpectedly plunged a knife into the adolescent detainee in 2017 after treating his wounds in Iraq.

But the government was floored by what came next: Scott took the blame for the killing, saying he suffocated the boy in an act of mercy shortly after Gallagher stabbed him.

It was a stunning twist in an already tumultuous case -- illustrating the challenges of prosecuting war crimes cases, especially those involving members of the secretive special forces. The turn of events also exposed the risk that prosecutors take when immunity is granted to witnesses.

"You're assuming a certain amount of risk that you know what they're going to say and that what they're going to say is truthful," said Retired Army Maj. Gen. John Altenburg Jr., who has handled or oversaw about 1,000 military trials. "If you get surprised, you get surprised. That's what can happen when you have cases like this."

Scott wanted to invoke his Fifth Amendment right against self-incrimination and not answer questions when he was called by the prosecution. But he was granted immunity and ordered to testify.

After Scott made the declaration, a visibly angry prosecutor accused him of lying, saying Scott had told investigators a different story several times and changed it only after he was granted immunity, which 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."

The testimony was 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.

The defence 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 did not want him promoted.

When asked if Scott's testimony, which did not dispute that Gallagher stabbed the militant in his care, would mean a lesser charge of premeditated attempted murder for the special operator, defence attorney Tim Parlatore said it only proved one thing: "It means he's not guilty," he said.

Gallagher's wife said she was relieved that the truth was finally emerging.

"To hear today that someone's finally had the bravery to stand up for the truth was refreshing after all these years," Andrea Gallagher said as she stood with her husband and their two children outside of court.

The Navy said in a statement it will not drop the premediated murder charge and that it's up to jurors to decide the credibility of witnesses.

Before the stabbing, Scott said that he and Gallagher had stabilized the sedated prisoner who had been 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 patient 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 had 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 said no one asked him how the patient died.

Four SEALs and one former SEAL have taken the stand. Several have described instances when they said Gallagher fired at civilians, once shooting an old man.

Gallagher's case has drawn the attention of President Donald Trump, who is reportedly considering a pardon.

The trial came after a judge's removed the lead prosecutor over a bungled effort to track emails sent to defence lawyers in order to find the source of leaks to the media.

The judge determined that the effort violated Gallagher's constitutional rights and reduced the maximum possible punishment from life in prison without parole to the possibility of parole.

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

The Navy has said the jury can convict Gallagher of a lesser charge, such as premeditated attempted murder, which carries a maximum penalty of life with the possibility of parole. There is no minimum sentence.

------

Melley reported from Los Angeles