Shortly before Bradley Manning was arrested in Iraq under suspicion of being the source of the vast transfer of US state secrets to WikiLeaks, he is alleged to have entered into a web chat with the hacker Adrian Lamo using the handle bradass87. "I'm honestly scared," the anonymous individual wrote. "I have no one I trust, I need a lot of help."

That cry for assistance was a gross under-estimation of the trouble that was about to befall Manning, judging from his testimony on Thursday. In his first publicly spoken words since his arrest in May 2010, delivered at a pre-trial hearing at Fort Meade in Maryland, the soldier painted a picture of a Kafkaesque world into which he was sucked and in which he would languish for almost one excruciating year.

Over more than six hours of intense questioning by his defence lawyer, David Coombs, Manning, 24, set out for the court what he described as the darkness and absurdity of his first year in captivity. The more he protested the harsh conditions under which he was being held, the more that was taken as evidence that he was a suicide risk, leading to yet more tightening of the restrictions imposed upon him.

He related how he turned for help to one particular member of staff at the brig at Quantico marine base in Virginia where he was taken in July 2010. He assumed that Staff Sergeant Pataki was on his side, so opened up to him.

"I wanted to convey the fact that I'd been on the [restrictive regime] for a long time. I'm not doing anything to harm myself. I'm not throwing myself against walls, or jumping up or down, or putting my head in the toilet."

Manning told Pataki that "if I was a danger to myself I would act out more". He used his underwear and flip-flops as an example, insisting that "if I really wanted to hurt myself I could use things now: underwear, flip-flops, they could potentially be used as something to harm oneself".

The conversation took place in March 2011, eight months into his stay at Quantico where he had been held in the most extreme conditions. He was under constant observation, made to go to the toilet in full view of the guards, had all possessions removed from his cell, spent at times only 20 minutes outside his cell and even then was always chained in hand and leg irons.

Manning felt good about his interaction with Pataki. "I felt like he was listening and understanding, and he smiled a little. I thought I'd actually started to get through to him."

That night guards arrived at his cell and ordered him to strip naked. He was left without any clothes overnight, and the following morning made to stand outside his cell and stand to attention at the brig count, still nude, as officers inspected him.

The humiliating ritual continued for several days, and right until the day he was transferred from Quantico on 20 April 2011 he had his underwear removed every night. The brig authorities later stated that in their view the exceptional depriving of an inmate's underpants was a necessary precaution, in the light of his ominous comments about using his underwear and flip-flops to harm himself.

If the marine commanders were guided in their treatment of Manning, as they said they were, by fears that he was suicidal, that assessment would certainly have been merited at the beginning of his captivity. Manning began his epic testimony by describing how he had a virtual mental breakdown soon after he was taken to Camp Arifjan in Kuwait following his initial arrest.

He was clearly terrified by the uncertainty in which he suddenly found himself. He had, by his own admission, recently committed a massive dump of government information from secure military computers to the website WikiLeaks, and now he was in the hands of army jailers with no knowledge about what was going to happen to him.

"I didn't know what was going on, I didn't have formal charges or anything, my interactions were very limited with anybody else, so it was very draining."

He was put on a schedule whereby he would be woken up at 10 o'clock at night and given lights out at 2 o'clock in the afternoon. "My nights blended into my days and my days into nights," he told the court.

The isolation also got to him. "I'm generally a pretty socially extrovert person, but being for long periods of time by myself I was in a pretty stressed situation. I began to really deteriorate. I was anxious all the time, everything became more insular."

The guards stopped taking him out of his cell so that he became entirely cut off from human company. "Someone tried to explain to me why, but I was a mess, I was starting to fall apart."

Military police began coming into his cell in a tent in the Kuwaiti desert two or three times a day doing what they called a "shakedown": searching the cell and tearing it apart in the process.

Then the breakdown happened. He was found to have made a noose out of bedsheets, though he told the court he doesn't recall that now. He was found one day screaming, babbling and banging his head against his tent cell.

"My world just shrank to Camp Arifjan and then my cage. I remember thinking: I'm going to die. I'm stuck here and I'm going to die in animal cage."

He remembers telling the camp psychiatrist in Kuwait that he had contemplated suicide. "I didn't want to die but I wanted to get out of the cage. I conveyed to him that if I could be successful in committing suicide, I would."

When he was asked to fill out a form by the camp guards, he answered a question on whether he had any suicidal thoughts with the comment: "Forever planning, never acting."

Amid such alarming signals of potential self-harm, he was put on anti-depression and anti-anxiety drugs and put on suicide watch. By the time he was moved from Kuwait to Quantico on 29 July, he told the court, he was already feeling substantially better and well on the way to recovery.

It is one of the great ironies of his story that when he arrived at Quantico he was at first delighted. "It wasn't the ideal environment in Quantico," Manning said to chuckles around the court. "But it had air conditioning, solid floors, hot and cold running water. It was great to be on continental United States soil again."

His buoyant spirits soon received a knock, he went on. He was submitted to what he called a "shark attack" by the reception officers at Quantico. Though he was an army soldier, he had been transferred to a marine base, part of the navy, and he didn't understand any of their routines or vocabulary.

"They were trying to show you they were in charge. 'Face the bulkhead!' they ordered, but I didn't know what a bulkhead was. Everything I did was wrong because I didn't know."

Given his behaviour in Kuwait, Manning was put on suicide watch when he arrived at Quantico. He was under permanent observation from guards who sat in a booth right outside his cell, most of his possessions were removed, he was made to sleep on a pillowless suicide mattress with only a suicide blanket – one that could not be used to cause self-harm – to lie under at night.

In a theatrical move, Coombs had placed white tape on the floor of the court room in exactly the dimensions of Manning's cell throughout the nine months he stayed in Quantico – 6ft by 8ft (180cm by 240cm). The cell contained a toilet that was in the line of vision of the observation booth, and he was not allowed toilet paper. When he needed it, he told the court, he would stand to attention by the front bars of the cell and shout out to the observation guards: "Lance Corporal Detainee Manning requests toilet paper!"

As Manning walked around the diminutive virtual space of the cell, the thought occurred that in this regard at least he was lucky to be so small. At 5ft 2in (157cm) he was towered over by Coombs as they circled each other in the courtroom.

Manning related how he tried to keep healthy and sane within the tiny confines. For the first few weeks of his confinement in Quantico he was allowed only 20 minutes outside the cell, known as a "sunshine call". Even then whenever he left his cell – and this remained the case throughout his nine months at the marine brig – he was put into full restraint: his hands were handcuffed to a leather belt around his waist and his legs put in irons, which meant that he could not walk without a staff member holding him.

"I'm not a great fan of winter, it's the solstice and it's dark," Manning said at one point. "I'm a fan of sunshine." So it was particularly hard for him that there was no natural light in his cell.

"If you took your head and put it on the cell door and looked through the crack, you could see down the hall the reflection of the window," Manning told the court, adding that "there was a skylight. You could see the reflection of the reflection of it if you angled your face on the door of the cell."

At night the light situation was even worse. Because he was considered a possible risk of self-harm throughout his time at Quantico, he was under observation throughout the night, with a fluorescent light located right outside the cell blazing into his eyes. While asleep he would frequently cover his eyes with his suicide blanket, or turn on to his side away from the light, and on those occasions, sometimes three times a night, the guards would bang on his cell bars to wake him up so they could see his face.

He sought solace wherever he could find it. Occasionally he was allowed to read a book his family had sent him. "I read a lot of philosophy, a lot of history. I'm more of a non-fiction reader though I like realistic fiction like John Grisham. Richard Dawkins would be an interesting author."

He was forbidden from taking exercise in his cell, and given that he was allowed out of the cell for at most one hour a day for the entire nine months at Quantico, he started to be creative about finding a way around the prohibition. "I would practise various dance moves. Dancing wasn't unauthorised as exercise."

He would also practise what he called resistance training – pretending to be lifting weights in his cell when he had no weights. "I would pace around, walk around, shuffling, any type of movement. I was trying to move around as much as I could."

As a man who from a young age has been noted for his bright intelligence, and who until his arrest was passionate about interactive computer technology and computer games, Manning also found an unconventional way to keep his mind sharp in the cell. He would make faces at himself in the mirror, the one bit of furniture in the cell other than his bed, sink and toilet.

"The most entertaining thing in there was the mirror. You can interact with yourself. I spent a lot of time with that mirror," he told the court, provoking laughter.

Why did he do all those things, Coombs asked him.

"Boredom. Just sheer out-of-my-mind boredom."

But that is where the problems for Manning started. He was trying to keep himself sane in unthinkably isolated and segregated conditions. But his military captors chose to interpret such behaviour as quite the opposite, a sign that he was still suicidal.

The truth was very much otherwise. Three Quantico forensic psychiatrists who gave evidence to the court this week agreed that within days of arriving at the marine base Manning had recovered his mental health and was no longer a risk to himself. They consistently recommended that the soldier be put on a much looser regime.

But the authorities would not listen. All they would do was to lower his status from "suicide risk" to "prevention of injury order" or PoI, a theoretically more relaxed set of rules that in practice was in almost all regards just as restrictive as its predecessor.

Other military expert witnesses this week compared the PoI regime unfavourably with Guantánamo and death row, saying that it was more stressful on the inmate than either. Yet the Quantico authorities cited precisely those activities that Manning had used to keep his hopes alive to argue for him remaining on the PoI order. They referred to the fact that he danced in his cell, did fantasy weightlifting and made strange faces in the mirror. They even referred to the fact that he played peek-a-boo with the guards as a sign that he was at serious risk of suicide.

They also continuously referred back to that comment he'd made in Kuwait – "Always planning, never acting" – even though that had been almost a year earlier.

Before he left Quantico Manning made one final attempt to persuade the brig commander, Chief Warrant Officer Barnes, that he was perfectly well and was no danger to himself. "I told her that the conditions I was under struck me as absurd. I tried to tell her that's how I saw it – the absurdity of it."

Once more his attempt to act reasonably and rationally was interpreted as the opposite. Barnes grew angry, Manning testified, and said he was being disrespectful of a superior rank.

She warned Manning to be careful in future about what he said, as it might hurt him. "I took that as a threat," he told the court. "I realised at that point that to say any more would be a dangerous mistake."