A medic has shockingly testified in the war crimes trial of a Navy SEAL that he killed a young ISIS fighter and not the man accused, saying he decided to end the young militant's life to save him from being tortured by enemy forces.

Corey Scott was called as a prosecution witness on Thursday in the case against Edward Gallagher.

Gallagher has been charged with murdering the young ISIS militant by stabbing him multiple times in the neck and side but he denies it and claim she is being set up.

Two other SEALs have already testified against him, claiming he premeditated the murder and also shot at Iraqi civilians in Mosul in 2017.

On Thursday, Scott stunned the Navy court in San Diego by saying that while Gallagher stabbed the militant, he is the one who actually killed him.

He told the court he did it because he thought the boy would have been killed by Iraqi forces anyway and that he did not want him to be tortured.

'I knew he was going to die anyway, and wanted to save him from waking up to whatever would have happened to him,' he said.

Scroll down for video

Corey Scott (left in a court sketch) was called as a prosecution witness on Thursday in the case against Edward Gallagher. Gallagher (right) has been charged with murdering the young ISIS militant by stabbing him multiple times in the neck and side but he denies it and claim she is being set up.

He said Gallagher was not guilty of murder and added: 'He’s got a wife and family.

'I don’t think he should spend the rest of his life in prison.'

Scott, a doctor for Navy SEAL team seven, had been granted immunity for any alleged crimes of his own by the prosecution in exchange for cooperating with them.

Thursday was the first time he has ever claimed to have killed the boy himself and prosecutors accused him of lying.

'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,' Navy prosecutor, Lt. Brian John, told him.

Gallagher has long claimed that rather than stab the fighter, he used a knife to open his throat and insert a breathing tube.

He had a collapsed lung after being injured in a strike and could not breathe, he said.

The boy died in May 2017 after another group of SEALs radioed Gallagher's men to tell them they had him.

Gallagher and his men were on the battlefield and other witnesses testified that he said 'leave him, he's all mine.'

When they arrived, the boy was still alive, they said.

Gallagher approached him to give him aid but, they said, out of nowhere, he stabbed the boy in his neck and in his side.

One claimed that after the boy had died, he tried to justify it by calling him 'just an ISIS dirtbag'.

Gallagher is shown arriving in court with his wife Andrea on Thursday. She has supported him throughout

Photos shown to the court also showed him posing with the boy, holding him up by the head.

But Gallagher insists he only ever tried to give him aid.

On Thursday, Scott supported Gallagher's version of events and said that he put his thumb over the tube once Gallagher had inserted it.

He did admit that Gallagher stabbed the boy in the side but said he thought he would have survived it if he had not closed off his breathing tube.

Prosecutors were stunned by the admission and told the court it was the first they had ever heard of it.

Scott's testimony on Thursday is the first that supports Gallagher since the trial began on Monday.

Others have painted him as blood thirsty and say he relished in attacking Iraqis.

Gallagher has always denied murdering the fighter and says he is being set up by the other SEALs because they did not like his style of leadership.

His attorney says that they were angry that he had called them cowards.

One of the SEALs told the court on Tuesday that he'd also seen Gallagher shoot at an elderly Iraqi man and group of women as they collected water from a river.