AMMAN, Jordan — A Jordanian soldier charged with killing three U.S. Army Green Berets told a military court on Tuesday that he opened fire because he thought fellow Jordanian troops had come under attack but that he felt no resentment toward Americans.

The defendant, 1st Sgt. Marik al-Tuwayha, took the stand for the first time in his murder trial. He spoke in a low voice from a cage in the courtroom, his hands gripping the bars.

Al-Tuwayha has pleaded “not guilty” to murder charges in the November shooting of the U.S. military trainers who had come under fire at the gate of an air base in southern Jordan.

The judge has said the defendant has no apparent ties to terrorist groups.

Jordan is a U.S. ally in the region, including in the campaign against Islamic State extremists who control areas of neighboring Syria and Iraq.

The shooting at the al-Jafr air base appeared to strain those ties at one point.

Jordanian officials initially suggested the U.S. soldiers triggered the shooting by disobeying orders of Jordanian troops guarding the gate to the base.

Jordan later withdrew the claim.

The victims were 27-year-old Staff Sgt. Matthew C. Lewellen of Kirksville, Missouri; 30-year-old Staff Sgt. Kevin J. McEnroe of Tucson, Arizona; and 27-year-old Staff Sgt. James F. Moriarty of Kerrville, Texas.

In previous sessions, the court heard testimony from gate guards, a crime scene investigator and a forensics expert.

Al-Tuwayha said on Tuesday that he felt no resentment toward the Americans at the base, and that he had joked and chatted with them over tea in the past. His comments were barely audible, and the judge repeated them for the court.

Witnesses have said that a four-car convoy approached the entrance of the base sometime before noon on Nov. 4.

The first vehicle passed through an outer and an inner gate, entering the base safely. Three more vehicles carrying U.S. troops stood between the outer and inner gate when Jordanian gate guards said they heard a low sound, possibly a pistol shot, from the direction of the convoy.

Three of the gate guards said they held their fire after hearing the pistol because they couldn’t identify the exact source of the sound.

At the time, the defendant was in the guard house, close to the inner barrier, to recharge the battery of his wireless device, witnesses have said.

Al-Tuwayha said Tuesday he heard a pistol shot coming from the direction of the American convoy. He said he could not determine the exact source of the sound because he couldn’t see from inside the guard house.

He said he opened fire because he feared that his colleagues were coming under attack. He said he initially opened fire from inside the guard house, believing he was complying with rules of engagement. He said he didn’t aim at anything or anyone and had “no intention of killing anyone.”

At some point, he emerged from the guard house and continued shooting, according to security camera video of the incident that was described previously by the fathers of two of the slain American soldiers. The video has not been made public.

One of the bereaved fathers has said the shooting continued for several minutes. Lewellen and McEnroe were killed on the spot, while Moriarty and a surviving U.S. soldier escaped from their vehicles, returned fire and seriously wounded the Jordanian soldier.

A crime scene investigator previously told the court that multiple rounds were fired from two M-16 assault rifles issued to Jordanian troops, including from inside the guard house where cartridges were later found.

A total of 78 bullets were fired from the M-16 rifles and 19 bullets were fired from pistols used by U.S. troops. The investigator said each of the three vehicles carrying Americans was hit by gunfire.

The military court prosecutor said Tuesday that al-Tuwayha fired 63 bullets from his rifle.

The prosecutor did not say who fired from the second M-16, but a witness had previously said that shots had also been fired in the air.

The next hearing is set for Wednesday.

If convicted, al-Tuwayha faces life in prison.