Ghaith Abdul-Ahad was seized by Gaddafi forces in the town of Zawiya during the first weeks of the Libyan uprising and held for two weeks. In his first dispatch from post Gaddafi Libya, he describes his return to his former cell and his encounters with his erstwhile jailers

I remembered that Hatem was tall and wore spectacles and had a pudgy, smiling face that didn't seem to fit his profession. But I was not prepared for the warmth he showed. Meeting him again was like encountering an old friend. The questions came tumbling out. "How are you? How did you find me? What happened after you left?"

In the early days of the Libyan revolution, Hatem had been the officer in charge of my custody in during two weeks of solitary confinement inside one of Gaddafi's notorious Tripoli prisons. The last time I saw him we had been separated by an iron door. Only his face and his hands had been visible as he passed food through the tiny hatch.

Outside, the revolution was fermenting in the mountains and the streets of the coastal cities, but inside the prison the officers had been confident. Hatem was angry, frustrated, and sometimes deluded, ranting against the rebels – "the rats", as Gaddafi had dubbed them – the agents of Nato, and the crusaders plotting against his country. He accused journalists of being spies and enemies of Libya.

"What do you want from us?" he would ask every night as he stood outside my cell, drinking coffee. Sometimes, in a sudden burst of generosity, he would pass a small cup through the hatch for me. But he never came inside. "We love Gaddafi. We love him. What's happening is all because of you journalists. It's a plot by Nato and Arab reactionary countries."

Months after I had been released, and after Tripoli had fallen to the rebels, I went to look for Hatem. I wanted to ask him if he believed in what he was telling me or if it was all part of an act. Through him I wanted to tell the story of the security apparatus of the regime in its final days and what's happening to them now.

The mood in Tripoli was jubilant. In Martyrs' Square car horns were honking, children waved flags, women ululated and celebratory bursts of gunfire peppered the sky.

But the signs of the difficult relationship between the old and the new were surfacing. In front of ministries and public buildings there were small demonstrations against old regime officials. In my hotel room I spread my clues out on the bed. I knew what Hatem looked like. I knew he worked in a prison of one of the many security services, but that was it. How do you look for the defeated in the city of victors?

For a city with a single main hospital and one university, Tripoli was well-equipped when it came to prisons. There was the infamous Abu Salim prison, where 1,200 inmates were killed in 1996; the military police prison; the criminal investigation prison. In the last days of the revolution, farms and company offices were converted into prisons and every military or security unit ran its own detention centre.

We drove to the prison of the external security service, where other journalists had been held. The main building was like a dead animal, its spine broken in half by a massive bomb. Around it were manicured lawns and a basketball court and pleasant gardens, smaller white buildings scattered among the shrubs and trees.

With a government guard I went into one of the smaller buildings. Inside, it was efficiently divided into small cells. But they were bigger and lighter than my cell. We walked into another building. During my incarceration I was blindfolded all the time while outside my cell. But I had drawn a map of the place in my mind. I thought I'd recognise it when I saw it. I didn't. Instead, recognition came in flashbacks. I am crouching blindfolded facing a wall, three men in military uniform sifting through our belongings. The room smells of hospital detergent. I can see a man in a surgical mask and rubber gloves. The Brazilian journalist I was captured with [Andrei Netto, who was released a few days later] is led away. A big door slams ...

Now the realisation hits me. I'm in that room again. A few bits of furniture lie overturned on the dark grey, mottled carpet. I can taste the feeling of terror that came over me in this place a few short months ago.

Flashback: three faceless officers interrogating me for hours. "You can tell us what we need to know or we can make you talk."

We walked further, into a long neon-lit corridor, huge black doors lining one side. Behind them lay dark cells with grimy mattresses, filthy, broken toilets. The ghosts of guards and their captives lingered in the air. Here, then. It was here.

I walked into different cells and wondered what had happened to the other inmates: the man who screamed all night, the Egyptian, the Tunisian, the American. "That building was called the Market," a former intelligence officer told me later. "There were food and clothing shops for the members of the service, officers who had to spend weeks without leaving would shop there. Then they converted it into a prison for high-value people, VIPs."

What about torture?, I asked him. "Sometimes they would put the detainees in dog cages, just to scare them. It depended on the officer. Some would go out of their way to harm prisoners."

I was not beaten or tortured but I could hear the sounds of people getting beaten through the walls. The doctor had told me that the foreigners were treated differently. "Where they kept you the treatment was considered luxury compared to the guys who where kept in the back prison or the with the dogs. "The foreigners were not beaten but they beat and tortured the locals. They wouldn't beat the prisoners in front of me, but I did see officers walking with sticks made of palm tree reeds. But even without beating life was horrible, the dark, small dungeons, the fear, the sounds of the dogs. They terrorised the people in these dark cells. You lose your humanity, you lose your respect."

I asked Saleh, a former intelligence officer who spent some time in jail for aiding the rebels in the first days of the uprising, to help me track some of the former officers who worked in the "Market" prison. Two days later we managed to locate one of the guards that I knew. Abdul Razaq was lean and medium height, handsome with grey hair. I remembered him to be always in a good mood but now he looked years older. Dark, sagging rings had formed under his twitching eyes.

We sat outside his house in a small, dusty lane of low, brick houses in Tajoura. The metal shutters of shops were down but neighbours stood outside the high gates of their houses talking. He was scared and anxious. He didn't know why I had come to see him, and he was worried that I might be seeking some form of revenge. His daughters were playing around him like three little kittens. He sent one inside to bring tea. She came back carrying a white plastic tray, that had a silver teapot and three very small cups. He held the teapot high while pouring.

"Look, I am still in charge of feeding you," he said, attempting to break the awkwardness of sharing tea with his prisoner. "When you were there things were good, after you left [mid-March) the prisons started filling. In the small cells we started putting five or six. The big ones held up to 60. The corridors were filled with detainees. It became horrible."

For you or the prisoners?, I asked, half-jokingly. "For us," he said seriously, handing me the small cup. "Imagine the smell, of all those people squeezed together, we went there with masks on.

"When Nato started bombing us, I knew it was over. We can detain people and put them in jail but we can't resist Nato. We all started to defect."

"I couldn't handle the pressure after that," said Razaq. "I asked for a medical leave and I stayed in my house from June.

"I didn't sign up for this, I didn't join the service to be under Nato bombing. Now in the middle of the night I jump. My wife says, what's happening? I say, bombs, bombs. She says, go back to sleep, these are your dreams."

I asked him if he knew the officer I was looking for. He said yes. He asked one of his daughters to bring him his phone and made a call and 10 minutes later the officer came. Tall and striding confidently, it was Hatem.

He was smiling. Abdul Razaq offered him a glass of tea. He drank it and kept asking how I found him.

It was a strange moment. We were meeting like old friends. There was some kind of shared camaraderie between us. Yet can I draw a line between the man and his job? Can you befriend your jailer? He told me about what happened to the jail after I left. He spoke about it fondly, as if it was a place filled with happy memories.

"We knew Nato was going to bomb us, we sent most of the prisoners to another place, a company compound. But we stayed in the headquarters. Most of the nights you can hear the sound of missiles and then you hear the explosion. That night we just heard a huge explosion, the floor underneath my feet went and then there was another explosion, everything was covered with smoke and dust, all the doors burst open from the explosion. The building that was hit was our communication centre. The monitoring equipment was there and we could listen to any phone number we wanted. How do you think we found you?" he smiled.

"We could have [survived] if it was Nato alone, but Libya was infested with spies," Hatem added bitterly. "So many people here defecting in the end – not because they didn't agree or benefit from the regime, but because they knew it was game over."

Burst into the cell

I asked the two officers about another jailer. He was short, stocky and rude and used to burst into the cell in the middle of the night asking random questions. A couple of times he blindfolded me and handcuffed me and marched me around the corridors, just to then bring me back to the cell.

"This guy had a psychological problem," said Hatem. "Sometimes he was nice, and then sometimes something in him clicks and he becomes very aggressive, making life for prisoners hell. In the last days there was paranoia. They were throwing anyone and everyone in prison. The [Gaddafi] militias would grab people in the street, take their money and phones, and hand them to us. We started refusing to receive detainees."

Hatem stood up: "What are you up to now? Let's drive around town."

Tripoli has the most beautiful sunsets in the world. A burning orange disc was sinking slowly into the sea. I watched his face change every time we passed a checkpoint. He would force a meek, uneasy smile, the smile of someone not used to relinquishing power.

People like Hatem are being detained all over Tripoli. They are stopped at checkpoints and pulled out of their cars when they show their ID cards.

"This is a very dangerous time," Hatem said.

"No one has credibility. They call you [the rebels] they say we need to talk to you, you go, and you find yourself detained. The Gaddafi regime used to detain people and no one would know where they are and who detained them. Now it's the same thing."

There comes a point when people know that the days of the regime are over. This point comes at different times to different people. Saleh switched sides in March. Abdul Razaq lost his nerve in June. I asked Hatem, when did he reach that point?

"I never defected. I worked until 20 August (the day rebels entered Tripoli.) Only then I couldn't go to work because of the fighting. But I didn't pick up a gun and fight the rebels. Those are Libyans. I think they are mistaken, but it's not my job to fight in the streets."

The perfect disc was half-submerged now in the water. Families were filling the small playground on the edge of the sea.

A traffic jam built up in front of Martyrs' Square, honking and selling flags.

"The same people who were carrying the green flag in Gaddafi's one million people march are the same people carrying the flag of the revolution," Hatem says.

"Gaddafi didn't import people to cheer for him. They were Libyans. It's fine. People can change their mind." But he adds it is wrong for those same people now to claim they had nothing to do with the regime, and to say that everyone who did should be locked up. Two days later, I met Hatem again. We sat in an old cafe in the centre of old Tripoli, in the courtyard of a beautiful old Italian palazzo.

Men smoked and discussed the politics of post-Gaddafi Libya. Hatem ordered two machyata [machiatos]. I asked Hatem if he or others tortured people in the prison.

"Look, what do you expect from us? We are an intelligence service. We needed to get confessions from people, but it all depends on the officer. Some officers enjoy the pressure on people. Some just do it to get information. Most of the times you don't need to torture people to get information – you just buy it off them."

The more I talked to Hatem, the more resentfully he spoke of the rebel movement.

"Muammar [Gaddafi] is to be blamed for all that happened," he said. "He should have left from the beginning. He was great in his foreign policy. I knew as a Libyan nothing can happen to me overseas because the regime will defend us. But at home, he was a disaster. His sons looted all the foreign investment and they left the country hungry, and when the war happened the poor people became the victims."

In words almost identical to that of Iraqi army officers who found themselves shunned or hunted after the fall of Baghdad, he said: "Five of my friends have been killed in the last month. We were almost 10,000 members of the intelligence service.

"We haven't been paid for two months now. In another month or two, 5,000 will start to rebel against the transitional council if they continue with the assassinations of the former officers. Then we are heading to civil war."