Journalists working for the BBC in Libya have been arrested, tortured and subjected to a mock execution by security forces of Colonel Muammar Gaddafi's regime.

The shocking account of their experiences, including being held in a cage in a militia barracks while others were tortured around them, was made available to media colleagues in Tripoli after the men had been released and left the country.

At one point during their captivity the men say they had shots fired past their heads as they were led into a barracks.

One of the men was attacked repeatedly with fists, boots, rifle butts, a stick and piece of pipe. He also described trying to help other victims of torture whom they saw, some of whom had had their ribs broken during beatings.

The ordeal represents the most serious incident yet involving the targeting of the international media and may offer an insight into the fate of many of those opposition supporters who have been rounded up during the regime's crackdown on its opponents.

It also offers the first real eyewitness depiction of conditions endured by those arrested by the regime, including those whose only crime has been to talk to foreign journalists.

A reporter for the BBC Arabic service, Feras Killani, a Palestinian refugee with a Syrian passport and Turkish cameraman Goktay Koraltan, were arrested on Monday with Chris Cobb-Smith, a British citizen, at a checkpoint in Zahra, six miles from the besieged town of Zawiya 30 miles from Tripoli.

The two journalists say they were kicked and punched and beaten to the floor with rifle butts while being interrogated as suspected "British spies" despite having permission to work in Libya. Cobb-Smith was not assaulted.

Killani described being taken to a "black and white barracks" at first where he was questioned aggressively by a captain with three stars on his shoulders before being taken behind a building and assaulted.

"[There] was lots of bad language," Killani saidon Wednesday. "When I tried to respond he took me out to the car park behind the guardroom.

"Then he started hitting me without saying anything. First with his fist, then boots, then knees. Then he found a plastic pipe on the ground and beat me with that. Then one of the soldiers gave him a long stick. I'm standing trying to protect myself, I'm trying to tell him we're working, I'm a Palestinian, I have a good impression of the country. He knew who we were [that we were journalists] and what we were doing."

"I think there was something personal against me," he added. "They knew me and the sort of coverage I had been doing, especially from Tajoura the Friday before. They don't like us or Arabiya or Jazeera."

Warned by his assailants not to tell the others he had been beaten, he was led back to the room where Koraltan and Cobb-Smith were being held, and told not to say a word.

"The captain asked the other guards to come and started to hit and kick me. They hit me with a stick, they used their army boots on me, and their knees. It made it worse that I was a Palestinian – and they said we were all spies. Sometimes they said I was a journalist who was covering stories in a bad way.

"[Then] they put us in a car and the captain, the one who beat me, told the guard if they say one word kill them."

Taken back to Tripoli under armed guard, the three men were taken to a military barracks, as Cobb-Smith explains: "I thought it was a good sign we were going to a legitimate barracks, it was a compound with an eagle on the gate, but we went past the front gate down a back street.

"There was a building down the side, attached to the barracks and not behind the perimeter wall. It was a dirty scruffy little compound about 100 metres square."

Most chilling was what the men could see in the middle of the compound, a large metal cage. Once again Killani was immediately assaulted, knocked to the ground by four or five men who, when he was on his knees, cocked their rifles as if to shoot him. The three men were then placed in the cage."

Next, Killani was taken into what he thought was a guardroom. "[It was] plain concrete with a heavy door. They took me inside and left me alone for a few minutes and then they started. After 15 minutes they were hitting me and kicking me very hard, the worst since I arrived, they put cuffs on my legs. They put three layers over my face, something like a surgical hat, the thing a nurse would wear but over my face.

"I was on the floor on my side, hands and feet cuffed, lying half on a mattress, and they were beating me. They were saying I'm a spy working for British intelligence, they asked me about the $400 and £60 and some dinars I was carrying. They asked if I was given the money from the intelligence department I worked for."

"I could hear screams," recalled Koraltan. In the meantime Cobb-Smith had managed to discreetly call the BBC at their hotel with a phone he had hidden, and alerted them to the seriousness of their situation.

Killani by now had a mask taped on his face and was struggling to breathe. The two other men were having masks taped to their faces.

Taken out of the cage one by one, Koraltan could hear guns being cocked again and thought he would be executed. "I was really scared, panicked; Chris was trying to say to me it was going to be OK. I thought they were going to kill us and blame al-Qaida or the rebels."

Killani was kept in the cage, but now his captors had taken off the cuffs binding him, apparently believing his protestations that he was a journalist. With him now were other prisoners.

Killani spent the night doing what he could for the other prisoners, who were all handcuffed. Some of them told him they had been arrested because their phone calls had been intercepted – including ones to the foreign media. "I spent the night in a cell. There were 10 to 12 men from Zawiya. Some were in a bad situation, with broken ribs.

"I was looking out of the cage. Cars were coming and going. I saw them bring in a guy and three girls, prisoners, too. Two of them told me they had broken ribs. The four who were masked, I helped them breathe by lifting their masks, saw they had been badly beaten.

"The four who were masked said they had been three days without food and with arms and legs cuffed. They said where they were now was like heaven compared to where they had been. They said they had been tortured for three days, and were from Zawiya. The four all knew each other. They didn't want to talk much. None of them said they were involved in fighting but the guard told me. Their hands were swollen and so were their faces."

The next morning, after a frantic effort by the BBC's team to locate the men and secure their release, they were taken to another barracks. Cobb-Smith could hear screams of pain coming from the second floor and could see people being moved around hooded and handcuffed.

"We were lined up against the wall facing it. I stepped aside to face a gap so they wouldn't be able to smash my face into the wall. A man with a small submachine gun was putting it to the nape of everyone's neck in turn. He pointed the barrel at each of us. When he got to me at the end of the line, he pulled the trigger twice. The shots went past my ear.

"After the shooting incident, one man who spoke very good English, almost Oxford English, came to ask who we were, home towns and so on. He was very pleasant, ordered them to cut off our handcuffs. When he had filled in the paperwork, it was suddenly all over. They took us to their rest room. It was a charm offensive, packets of cigarettes, tea, coffee, offers of food." Finally the men were set free.

A Foreign Office spokesman said: "We were aware of the incident and have been in contact with the BBC throughout, facilitating contacts to ensure the safe release of those detained.

"We condemn the abhorrent treatment of the team. This is yet another example of the horrific crimes being committed in Libya. The regime had invited journalists to Libya to see the truth.

"This truth is even more glaring today than it was before. As we have made clear there will be a day of reckoning for these abuses."