Image copyright Reuters

A decorated war hero has been found not guilty of murder and other serious crimes in a court-martial. But his trial shed light on the secretive world of the Navy Seals and the military justice system.

One morning during the trial, Edward Gallagher did a head roll, stretching his neck muscles while images of a fighter for the so-called Islamic State (IS) appeared on a computer screen in front of him.

Gallagher, 40, has a square, compact build, muscular arms and a deep suntan, the kind you get while driving a convertible in California (the white Mustang was parked in a reserved spot in front of the courthouse). Wife Andrea, parents Melissa and Joe, and younger brother, Sean, were sitting behind him in court.

Gallagher has been nominated for a Silver Star, one of the military's top honours. A platoon commander said he was a "deckplate leader", a term used by sailors to describe an exemplary chief.

The boy shown in the video was the only IS fighter to survive a battle in Mosul in the spring of 2017, and he had a physique so slender that a wristwatch fit around his bicep. He was slightly wounded in the battle, Frank Sheridan, an Irish-born forensic pathologist, told the jurors. Afterwards Iraqis handed the boy over to the Navy Seals for medical care in a military compound.

On that morning Gallagher knelt down next to the boy with a medical bag that contained his hunting knife, a bespoke model with a curved handle.

A courtroom confession

A year and a half later, Gallagher was charged with knifing the boy in the neck, killing him and posing with his body for a photo. The trained sniper was also charged with shooting two Iraqis, a girl in a flower-print hijab, and an elderly man walking near the Tigris River.

Gallagher's lawyers said the allegations were lies concocted by younger members of his platoon who struggled under his stern leadership. "He pushed them," says Gallagher's brother, Sean. "And they broke."

Sean says that his brother, who is trained as a medic, was tending to the boy. "It's verified that Eddie provided a crich in his neck," says Sean, using a colloquial term for an incision to open up a patient's airway. The boy died of his battle wounds, Sean tells me. "The accusation that my brother slashed him to finish him off," Sean says, was "fabricated".

Image caption "I've always believed my husband's innocent," Andrea Gallagher said outside court

Seven men, including one Navy Seal, sat on the jury, and six of them had served in combat. They found Gallagher not guilty of first-degree murder of the boy and attempted murder of the girl and the elderly man near the river. The jurors found him guilty of posing for photos with the boy's body.

For posing with the corpse, his rank and pay will be reduced. In addition, he was sentenced to four months confinement. He spent several months in a military jail while waiting for the trial to begin, however, and as a result he will not have to spend any more time behind bars.

The trial allowed a jury of military men to evaluate the allegations. It provided insight into the celebrated Navy Seals, special-warfare teams that helped carry out the raid that killed Osama bin Laden and rescued Capt Richard Phillips from Somali pirates. The trial also offered a glimpse into the opaque world of military justice.

For many, the verdict was a surprise. How could the prosecutors' case against Gallagher, an argument that was based on the accounts of seven witnesses, fall apart?

The most startling moment in the trial came when a witness, Corey Scott, said that he - not Gallagher - had killed the boy. Gallagher stabbed him, said Scott. But Scott said he had then asphyxiated the boy so he would not have to go back to IS leaders who might mistreat him.

Image caption Gallagher's lawyer Timothy Parlatore described him as an "old school, hard-charging warrior"

It was a dramatic moment in the trial, and many of those in the courtroom were sceptical of his story. After Scott described the murder, he looked at Gallagher and said he did not want him to spend his life in prison. Scott believed he had immunity, and for that reason felt he could speak openly about killing the boy.

One person involved in the case told me that the prosecutors and the defence lawyers all knew beforehand that a witness would confess to the killing. Upon hearing Scott's testimony, one of the prosecutors jumped from his chair and accused him of lying.

Band of brothers

Months before the trial, US President Donald Trump tweeted about Gallagher's "service to our Country" and later indicated he might grant him a pardon. The president's interest helped ensure that Gallagher had access to high-profile lawyers such as Marc Mukasey, who is also a lawyer for the Trump Organization.

After the verdict, the president appeared to take credit for the outcome.

Duncan Hunter, a Republican congressman from California and an Iraq war veteran, also championed Gallagher's cause. Hunter described Gallagher as a "war fighter who did the right thing".

Yet for many of the men who served with Gallagher, he was a Jekyll-and-Hyde character, a decorated chief who became a sociopathic killer in Mosul.

Loyalty among Seals is prized above all else, and the decision to "dime out" a chief, as Navy Times reporters put it, was unprecedented.

Prosecutors assembled more than a thousand pages of evidence. They used first-hand accounts of Gallagher's alleged crimes and his own words, remarks they thought revealed his nature: a man capable of great cruelty, someone who violated core American values.

'Got him with my hunting knife'

In 2017, Gallagher was on his eighth deployment. Along with other US troops, he was helping Iraqi forces take back Mosul from IS militants.

One of his former roommates testified that when Gallagher heard an IS fighter would be placed in their care, Gallagher said he wanted to take charge of him. "Lay off, he's mine," Gallagher told the other Seals.

Gallagher initially tended to the boy. Then according to seven members of the platoon, he stabbed him. One of them, Craig Miller, said he saw blood gush from the boy's jugular, a stream of liquid like the kind that one sees when a baby is "throwing up". Gallagher later texted his friends a photo of the dead boy: "Good story behind this," he wrote. "Got him with my hunting knife."

Gallagher was arrested on 11 September 2018 while he was visiting a treatment clinic in California where he was getting a check-up. Several weeks before the trial, many people thought that Gallagher would be sent to prison for decades.

Despite their reputation for high standards, the special warfare teams have been plagued by allegations of war crimes, violence and drug use. Concerned about the misconduct, senior military officers conducted a review of the teams earlier this year but did not release their conclusions to the public.

Image caption Navy ships were docked near the courthouse, and a bugle played each morning

The trial subjected the Navy Seals to rare scrutiny. It also offered insight into the way that military investigators and prosecutors operate.

The optics were not good. In June the chief prosecutor, Christopher Czaplak, was removed from the case. Defence lawyers said he had been secretly tracking their emails in an effort to determine who was leaking information to the media. In spite of what had once looked like overwhelming evidence against Gallagher, the government's case began to unravel.

The 'Sewing Circle'

Gallagher grew up in a military family with Irish roots. His father, Joe, graduated from the US Military Academy at West Point, the nation's most prestigious military college, in 1972 and served in the US Army. The Gallaghers lived in Beijing in the early 1980s and later moved to Fort Wayne, Indiana, where his father worked for a defence contractor.

Joe Gallagher and wife Melissa raised their boys with Old-World manners. Gallagher went to a Catholic high school and was "chivalrous", says his friend, Jessica Zimmerman, who is now a mental-health counsellor in Fort Wayne. "He's the guy that would hold the door for you."

Image copyright Courtesy of Sean McKelvey Image caption At a local VFW post, a Navy Seal said Edward Gallagher "needed serious help"

In Iraq, Gallagher was known for his confident, aggressive manner, traits that some men admired. But he made others uneasy.

Gallagher was put on trial in a city, San Diego, known for its conservative politics and its navy base. It is a city of about a million and a half with one of the nation's highest concentrations of military families and veterans. Navy ships are docked in the harbour, and outside the courtroom a bugle plays from five until eight, followed by the Star-Spangled Banner.

Within this patriotic world, the Navy Seals are known for their commitment to the nation and to each other. After returning home from Iraq, however, Craig Miller and others in Gallagher's platoon formed a WhatsApp group chat they described as a "Sewing Circle", an ironic term that evoked ladies doing embroidery. In fact, these men used the online forum to discuss Gallagher's alleged war crimes. They felt that he had crossed a line.

Tom Chaby, a retired Navy Seal who lives in Tampa, Florida, says: "Integrity - it's part of our ethos."

One of the group spoke to a commander at a Veterans of Foreign Wars (VFW) club, an organisation that is similar to the Royal British Legion, in late 2017. According to the Navy Times, he said that Gallagher had seemed unstable in Mosul and "needed serious help".

On a recent Sunday afternoon at that VFW club in California, a Navy Seal's wife sat at the bar, drinking beer from a plastic cup. Surrounded by US flags and menus on the wall ("Steak dinner is back!!"), she said Seals have their own way of handling matters. "If someone starts to get trigger-happy, they're ousted," she says. Gallagher did not want to go "peacefully", she says, and so the court-martial was convened.

In her estimation, there should never have been a trial, which turned into a public spectacle. As former Navy Seal Tom Chaby says: "We'd rather be quiet professionals." They believe strongly that Navy Seals who act in unethical ways should be punished and thrown out of the military. But they would prefer to take care of these issues in a private manner and away from the glare of the media.

Image caption San Diego, the home of the trial, has one of the nation's highest concentrations of military families

Commanders have increasingly relied on administrative measures to punish Seals instead of turning to military courts, and the number of courts-martial in the navy has gone down over the past decade, reports the Military Times. In 2008, there were about 750. Only about 280 were heard in 2017.

In one of them, a Navy Seal pleaded guilty to charges relating to the strangling death of a staff sergeant while they were on a secret mission in Mali.

To prepare their case against Gallagher, the government lawyers began to compile evidence from members of the "Sewing Circle" and others. But they had no DNA from the victim. There was no autopsy report. They did not even know the boy's name.

Searching for evidence

When US troops were accused of abusing detainees at Abu Ghraib prison in Iraq in 2003, people around the world reacted with outrage. But IS had waged a sophisticated online campaign of videotaped beheadings that was designed to showcase their capacity for brutality.

So when reports surfaced that Gallagher may have harmed an IS fighter, there was notably less indignation.

Evoking sympathy for an "ISIS terrorist", as the young militant was described on Fox News, posed a challenge.

Naval investigators went to Iraq to collect evidence in the autumn of 2018. More than 5,000 people were killed in Mosul during the war, and the place was filled with corpses - "like the horror movie Chucky with dead people everywhere", said one member of the search team.

But they could not find the boy's body, and so the prosecutors had no DNA or other evidence from him. This posed a problem for the government's lawyers during the trial.

Image caption "Eddie is very loyal," said Joe Gallagher about his son

The courthouse was located on the military base. The main clock in the courtroom had been mistakenly set wrong, and it was off by an hour and four minutes. For a civilian observer in the courtroom, the glitch embodied the spirit of the place: things were slightly different. There are seven jurors in a military court - not 12 as in a civilian trial - and they ask questions.

The jurors wanted to know how much blood pooled around the boy when he lay in the sandy soil in Iraq.

Sheridan, originally from Dublin, based his analysis on videos and photos taken of the boy in Iraq. He used a black pen to point at the boy's image on a computer screen and showed where blood had soaked into the sand.

A defence lawyer questioned Sheridan about his forensic analysis, and at one point the lawyer said: "There is no body." Sheridan seemed uncharacteristically taken aback. He reminded the lawyer that there was a body, but it had never been found.

"That kid - he's a human being," Sheridan told me later. "They may be trying to belittle that or cast it off. But we do have a young human being who's dead."

A Trump pardon

Throughout the trial, Gallagher acted as though it was not he who had been accused of wrongdoing but the investigators, prosecutors and witnesses. He and his lawyers appeared to be emboldened by the fact that they had the support of the president. Gallagher's self-righteous indignation became a fully-fledged legal strategy, and it was an effective one.

Timothy Parlatore and the other defence lawyers turned the tables on the prosecutors, saying they had pursued a "false narrative" and that special agents botched the investigation. They said that his words and actions - such as taking photos with a dead body - were part of the dark humour of a seasoned military man. Still, they said, he was not a murderer.

Trump made it clear in the late spring that he was considering a pardon for troops accused of war crimes. "We teach them how to be great fighters," the president told reporters, adding that "sometimes they get really treated very unfairly".

The president was tapping into a widely-held sentiment. People across the US - whether they are military veterans or civilians - understand that serving in combat can affect the emotional and psychological well-being of the troops. As a Navy Seal, Gallagher had been deployed multiple times, a fact that his lawyers pointed out to reporters and others.

Image copyright Getty Images Image caption Nixon, shown in 1970, helped secure early release for a US lieutenant who ordered killings in My Lai

It was not the first time that a US president has intervened in a war-crimes case. In one notorious incident William Calley, a US army lieutenant, ordered the killing of civilians in My Lai, a village in Vietnam, in 1969. He was sentenced to life in prison. Yet despite the stern punishment and the horrific nature of the crimes, he was - thanks to President Richard Nixon - freed after about three years.

More recently a group of law students tried to help a National Guard soldier who killed an Afghan prisoner and was himself put behind bars. The soldier was released in May and now speaks with regret about the man's death.

Prosecutors said Gallagher did not lash out in anger at the prisoner, instead he planned the murder and when the members of "Sewing Circle" tried to report his crimes, he allegedly threatened to kill them.

One of the members of the "Sewing Circle", Craig Miller, was seen in the prosecutor's waiting room. His hands were folded in his lap, and he fixed his eyes on the floor and looked "rigid", someone in the room told me later. "You think of the Navy Seals as being brave in combat," says another witness for the prosecution. "This is moral courage."

Parlatore said that Gallagher's accusers had a "personal animosity" towards him because he was an "old school, hard-charging warrior". Robert Breisch, a commander, testified that Gallagher's accusers were jealous and said they did not want to burnish "'the legend of Eddie Gallagher'".

In the courtroom, Parlatore struggled to rein in his client. Rules are posted: no mobile phones, gum or beverages. Gallagher broke all of them: he placed a can of Red Bull on the table. He chewed gum and looked at photos on a mobile phone. Outside the defence waiting room, his wife said impatiently: "How are we still here?"

In the final days of the trial, the prosecutors seemed frazzled. They struggled to find their notes.

'Like an Irish tragedy'

When the jury found Gallagher not guilty, he and his family rejoiced. Others said the trial was a sham. Members of an anti-war organisation for veterans, About Face, said the verdict was unsurprising, characterising the military justice as "rigged" and claiming that it supports "bad actors".

But some believe the court-martial has served another purpose. "The airing of concerns has caused the Seals to take a broader look at how they're enforcing discipline," says John Dehn, a former US army judge advocate, adding: "This will have a positive effect."

Image copyright Sandy Huffaker Image caption One of Edward Gallagher's lawyers, Marc Mukasey, celebrating after the verdict

Towards the end of the trial, I caught up with Gallagher's father, Joe. Holding two marble composition notebooks, he was waiting for a ride on a busy street across from the base. Cars roared past, and a street trolley banged along tracks.

"Eddie is very loyal," he says. A solid, imposing man, Joe Gallagher does not smile easily. But when he does, it lifts the heaviness from his face. "This is like an Irish tragedy," he says, referring to his son's trial, and adds jokingly: "If my grandmother were here, she'd say; 'It's the British that are behind it.'"

I told him about a bumper sticker that I had once seen: "If you're lucky enough to be Irish, you're lucky enough." He laughed loudly. A moment later his son pulled up in his convertible and they drove away.