The US soldier accused of leaking large numbers of secret documents to Wikileaks has apologised for hurting his country.

At a sentencing hearing in Fort Meade, Maryland, Bradley Manning said: “I’m sorry that my actions hurt people. I’m sorry that it hurt the United States.

“I’m apologising for the unexpected results of my actions. The last three years have been a learning experience for me.”

The soldier said he had mistakenly believed he could “change the world for the better”.

And he said that in retrospect, he should have worked “inside the system”.

“When I made these decisions I believed I was going to help people, not hurt people,” he said.

“Unfortunately, I can’t go back and change things.”

Ahead of Manning’s statement, Navy Captain David Moulton, a psychiatrist, testified that at the time of the leak Manning felt abandoned by friends and family and had hit a rough patch with his boyfriend amid an isolating deployment.

The psychiatrist interviewed Manning for 21 hours after his arrest.

Manning had also decided he wanted to become a woman, Capt Moulton said.

In psychiatric terms, Manning has a “gender identity disorder”, or “disturbance of one’s gender”, Capt Moulton said.

This is different from being gay, he added.

Manning faces up to 90 years in prison following his conviction in July on 20 espionage and other charges.

In May 2011, human rights campaigner Peter Tatchell described Manning as a “gay hero” and a “human rights defender”.

Manning had previously claimed that he was bullied over his sexuality during his time in the US Army - and he was reportedly disowned by his family after coming out.

In 2011, his father revealed he had “twisted his arm” to get him to join the army.

He said: “He didn’t want to join. But he needed structure in his life, he was aimless. I knew in my own life that joining the navy was the only thing that gave me structure, and everything’s been fine since then.”

The Obama administration said the leaks threatened valuable military and diplomatic sources.