Terry Holdbrooks arrived at Guantánamo detention camp in the summer of 2003 as a godless 19-year-old with a love of drinking, hard rock music and tattoos. By the time he left Cuba the following year, he had alienated his army colleagues, won the respect of the detainees and, most astonishingly, converted to Islam in a midnight ceremony in the presence of one of the detainees, who had become his mentor.

When I meet Holdbrooks, now 26 and named Mustafa Abdullah, he is wearing a black Muslim cap, a thick beard and long-sleeved traditional robes that almost obscure the tattoo on his right arm that reads "by demons be driven".

Holdbrooks grew up in Arizona, the only son of junkie parents who split up when he was seven years old. He was raised by his ex-hippie grandparents. Tired of being poor, determined not to follow in his parents' footsteps and keen to see the world, Holdbrooks signed up for the military. He was stationed with the 253rd Military Police Company, mostly doing administrative support work, when he was told he was to be deployed to Guantánamo.

During a two-week training course, the new guards took it in turns to act as detainees, and were also taken to Ground Zero. "We were not taught anything about Islam," he says. "We were shown videos of 11 September and all we kept being told was that the detainees were the worst of the worst – they were Bin Laden's drivers, Bin Laden's cooks, and these people will kill you the first chance they get."

Holdbrooks skims over the words, as if he is quoting from his forthcoming memoir, Traitor? "I was questioning things from day one," he says. "The first thing I saw was a kid who is all of 16 who had never seen the ocean, didn't know the world was round. I am sitting there thinking, what can he possibly know about the war on terror, what could he possibly know?"

Holdbrooks' duties at Guantánamo including cleaning, collecting rubbish, walking up and down the block to ensure detainees weren't passing anything between cells and ferrying them to and from interrogations. There were plenty of opportunities for communication. Holdbrooks's friendliness towards the detainees – they called him "the nice guard" – earned him unwelcome attention from his fellow guards.

"I didn't have a very high impression of my colleagues," he says. Many of them were "ridiculous Budweiser-drinking, cornbread-fed, tobacco-chewing drunks, racists and bigots" who blindly followed orders, and within months he had stopped talking to them altogether. There were frequent physical altercations: "One time one of them said to me, 'Hey, Holdbrooks, you know what we are going to do today? We are going to skull-fuck the Taliban out of you – you're a sympathiser and we don't like that." That led to another fist fight."

While the guards indulged in alcohol, porn and sports, Holdbrooks says he needed to learn how the detainees could endure abuse and still smile, while he was utterly miserable.

"I knew nothing about Islam prior to Guantánamo," he says, "so this was a complete culture shock to me. I wanted to learn as much I could, so I started talking to the detainees about politics, ethics and morals, and about their lives and cultural differences – we would talk all the time." What began as curiosity turned to disciplined study, with Holdbrooks spending at least an hour a day learning about Islam and talking in chatrooms online. Among those he talked to were the Tipton trio of British Muslims who featured in Michael Winterbottom's docudrama, The Road to Guantánamo; another was a man the other detainees referred to as the General – Moroccan-born Ahmed Errachidi, who had lived in Britain for 18 years, working as a chef, and spent five and a half years in Guantánamo accused of attending al-Qaida training camps. (He was later released and cleared of any wrongdoing.)

"We'd talk for hours and hours," Holdbrooks says. "We'd talk about books, about music, about philosophy: we would stay up all night and talk about religion."

Finally, six months into his time at Guantánamo, Holdbrooks was ready. On 29 December 2003, in the presence of Errachidi, he repeated the shahada, the statement of faith that is the sole requirement for converting to Islam: "There is no God but God and Muhammad is his prophet". The Guantánamo guard was now a Muslim.

He stopped drinking and even gave up music, because his interpretation of Islam suggested that this, too, was unacceptable. "It was not easy praying five times a day without my colleagues finding out," he says. "I told them I had to go the bathroom a lot."

Converting to Islam made Holdbrooks even more unhappy about his work – he felt he was worse off than the detainees. "They were having a lot more fun than I was. The Tipton trio were always playing tricks on the guards and the interrogators. The detainees had a lot of freedom in their confinement: I had all the freedoms they didn't have, but I was a slave to what the army wanted me to do."

This claim sounds implausible, but Holdbrooks says he is referring to their freedom of thought: he was impressed by the independence he saw in the detainees, compared to his fellow guards. This still seems a rather self-pitying analysis, particularly when he goes on to describe how he had seen detainees being tortured. "It was my job to take prisoners to interrogations, so sometimes I would sit and watch," he says. "I would see detainees who would be locked up for hours in horrible positions – for hours upon hours upon hours, in a room that might be 50 degrees or 60 degrees.

"There was one man who had defecated on himself and this ogre of an interrogator would douse water on him and then ask him if he was going to talk, and he would say he had nothing to talk about, and I remember thinking, what good is this going to accomplish? You cannot abuse and torture people and expect to get results that are accurate and credible."

In the summer of 2004, Holdbrooks left Guantánamo and was later discharged from the army on the grounds of a "general personality disorder". The alcohol problem that had plagued him before enlisting returned, and when his marriage dissolved, he sought solace in the old comforts of drinking, casual sex and music. "I was having nightmares about my time in Guantánamo," he says, "and I spent the best part of three years just trying to drink Guantánamo out of my mind."

Today, Holdbrooks is a practising Muslim again, but he does not seem to be at peace. There is a blankness in his gaze that hints at the scars his childhood and Guantánamo have left on him.

Why had this hard-living Arizona boy embraced Islam? The question needles me throughout our conversation. It is only when, towards the end, Holdbrooks reveals that his favourite words are "structure", "order" and "discipline" that the pieces fall into place. Holdbrooks's life had been a search for order: the regimentation of army life had appeared to offer structure, and when it let him down, he turned to religion.

Holdbrooks has more in common with his former colleagues than he realises: their allegiance to the army is matched by his adherence to faith. "Islam is a very disciplined, regimented faith and it requires a great deal of effort and conviction," he says. "I've had an unbelievable fascination with structure and order for as long as I can remember: structure, order and discipline – I just love them."