Somewhere in central Los Angeles, about 20 miles from LAX airport, there is a nondescript building housing a detention facility for foreigners who have violated US immigration and customs laws. I was driven there around 11pm on May 3, my hands painfully handcuffed behind my back as I sat crammed in one of several small, locked cages inside a security van. I saw glimpses of night-time urban LA through the metal bars as we drove, and shadowy figures of armed security officers when we arrived, two of whom took me inside. The handcuffs came off just before I was locked in a cell behind a thick glass wall and a heavy door. No bed, no chair, only two steel benches about a foot wide. There was a toilet in full view of anyone passing by, and of the video camera watching my every move. No pillow or blanket. A permanent fluorescent light and a television in one corner of the ceiling. It stayed on all night, tuned into a shopping channel.

After 10 minutes in the hot, barely breathable air, I panicked. I don't suffer from claustrophobia, but this enclosure triggered it. There was no guard in sight and no way of calling for help. I banged on the door and the glass wall. A male security officer finally approached and gave the newly arrived detainee a disinterested look. Our shouting voices were barely audible through the thick door. "What do you want?" he yelled. I said I didn't feel well. He walked away. I forced myself to calm down. I forced myself to use that toilet. I figured out a way of sleeping on the bench, on my side, for five minutes at a time, until the pain became unbearable, then resting in a sitting position and sleeping for another five minutes. I told myself it was for only one night.

As it turned out, I was to spend 26 hours in detention. My crime: I had flown in earlier that day to research an innocuous freelance assignment for the Guardian, but did not have a journalist's visa.

Since September 11 2001, any traveller to the US is treated as a potential security risk. The Patriot Act, introduced 45 days after 9/11, contains a chapter on Protecting The Border, with a detailed section on Enhanced Immigration Provision, in which the paragraph on Visa Security And Integrity follows those relating to protection against terrorism. In this spirit, the immigration and naturalisation service has been placed, since March 2003, under the jurisdiction of the new department of homeland security. One of its innovations was to revive a law that had been dormant since 1952, requiring journalists to apply for a special visa, known as I-visa, when visiting the US for professional reasons. Somewhere along the way, in the process of trying to develop a foolproof system of protecting itself against genuine threats, the US has lost the ability to distinguish between friend and foe. The price this powerful country is paying for living in fear is the price of its civil liberties.

None of this had been on my mind the night before, when I boarded my United Airlines flight from Heathrow. Sitting next to an intriguingly silent young man who could have been a porn star or a well camouflaged air marshal, I spent most of the 11-hour flight daydreaming about the city where he so clearly belonged and that I had never visited. My America had always been the east coast: as tourist, resident, journalist, novelist, I had never ventured much past the New York-Boston-Washington triangle. But I was glad that this brief assignment was taking me to sunkissed LA, and I was ready to succumb to LA's laid-back charm.

The queue for passport control was short. I presented my British passport and the green visa waiver form I had signed on the plane. The immigration official began by asking the usual questions about where I was staying and why I was travelling to the US. It brought back memories of another trip there to write a series of articles about post 9/11 America for the German weekly Die Zeit. I had written about commuters who preferred the safety of train travel to flying, and about a wounded New York that had become a city of survivors. I had seen a traumatised, no longer cockily immortal America in a profound state of mourning. But it had seemed to me that its newly acknowledged vulnerability was becoming its strength: stunned by an act of war on its own soil, Americans had been shocked into a sudden hunger for information about the world beyond their borders.

"I'm here to do some interviews," I said.

"With whom?" He wrote down the names, asked what the article was about and who had commissioned it. "So you're a journalist," he said, accusingly, and for the first time I sensed that, in his eyes, this was not a good thing to be. "I have to refer this to my supervisor," he said ominously, and asked me to move to a separate, enclosed area, where I was to wait to be "processed". Other travellers came, waited and went; I was beginning to feel my jetlag and some impatience. I asked how long I'd have to wait, but received no reply. Finally, an officer said, noncommittally, "It seems that we will probably have to deport you."

I'm not sure, but I think I laughed. Deport? Me? "Why?" I asked, incredulously.

"You came here as a journalist, and you don't have a journalist's visa." I had never heard of it. He swiftly produced the visa waiver (I-94W) I had signed on the plane, and pointed to what it said in tiny print: in addition to not being a drug smuggler, a Nazi or any other sort of criminal, I had inadvertently declared that I was not entering the US as a representative of foreign media ("You may not accept unauthorised employment or attend school or represent the foreign information media during your visit under this program").

My protestations that I had not noticed this caveat, nor been alerted to it, that I had travelled to the US on many occasions, both for work and pleasure, that I had, in fact, lived there as a permanent resident and that my husband was a US citizen, as was my New York-born daughter, all fell on deaf ears. He grinned. "You don't care, do you?" I said, with controlled anger. Then I backtracked, and assumed a begging, apologetic mode. In response, he told me I would have to be "interviewed", and that a decision would then be taken by yet another superior. This sounded hopeful.

Finally, after much scurrying around by officers, I was invited into an office and asked if I needed anything before we began. I requested a glass of water, which the interrogating officer brought me himself. He was a gentle, intelligent interrogator: the interview lasted several hours and consisted of a complete appraisal of my life, past and present, personal and professional. He needed information as diverse as my parents' names, the fee I would be paid for the article I was working on, what it was about, exactly, and, again, the names of people I was coming to interview. My biography was a confusing issue - I was born in one country, had lived in many others: who was I, exactly? For US immigration, my British passport was not enough of an identity. The officer said, pointedly, "You are Russian, yet you claim to be British", an accusation based on the fact that I was born in Moscow (though I never lived there). Your governor, went my mental reply, is Austrian, yet he claims to be American. After about three hours, during which I tried hard to fight jetlag and stay alert, we had produced several pages that were supposed to provide the invisible person in charge with enough material to say yes or no to my request to be allowed entry. My interrogator asked one last obligatory question, "Do you understand?"

"Yes, I understand," I sighed, and signed the form. The instant faxed response was an official, final refusal to enter the US for not having the appropriate visa. I'd have to go back to London to apply for it.

At this moment, the absurd but almost friendly banter between these men and myself underwent a sudden transformation. Their tone hardened as they said that their "rules" demanded that they now search my luggage. Before I could approach to observe them doing this, the officer who had originally referred me to his supervisor was unzipping my suitcase and rummaging inside. For the first time, I raised my voice: "How dare you touch my private things?"

"How dare you treat an American officer with disrespect?" he shouted back, indignantly. "Believe me, we have treated you with much more respect than other people. You should go to places like Iran, you'd see a big difference." The irony is that it is only "countries like Iran" (for example, Cuba, North Korea, Saudi Arabia, Zimbabwe) that have a visa requirement for journalists. It is unheard of in open societies, and, in spite of now being enforced in the US, is still so obscure that most journalists are not familiar with it. Thirteen foreign journalists were detained and deported from the US last year, 12 of them from LAX.

After my luggage search, the officer took some mugshots of me, then proceeded to fingerprint me. In the middle of this, my husband rang from London; he had somehow managed to locate my whereabouts, and I was allowed briefly to wipe the ink off my hands to take the call. Hearing his voice was a reminder of the real world I was beginning to feel cut off from.

Three female officers arrived to do a body search. As they slipped on rubber gloves, I blenched: what were they going to do, and could I resist? They were armed, they claimed to have the law on their side. I was an anonymous foreigner who had committed a felony, and "those were the rules". So I was groped, unpleasantly, though not as intimately as I had feared. Then came the next shock: two bulky, uniformed and armed security men handcuffed me, which they explained was the "rule when transporting detainees through the airport". I was marched between the two giants through an empty terminal to a detention room, where I sat in the company of two other detainees (we were not allowed to communicate) and eight sleepy guards, all men. I would have been happy to spend the night watching TV with them, as they agreed to switch the channel from local news (highlight: a bear was loose in an affluent LA neighbourhood) to sitcoms and soaps. Their job was indescribably boring, they were overstaffed with nothing to do, and so making sure I didn't extract a pen or my mobile phone from my luggage must have seemed a welcome break. I listened to their star-struck stories about actors they had recently seen at LAX. We laughed in the same places during Seinfeld, an eerie experience. I was beginning to think I could manage this: the trip was a write-off, of course, but I could easily survive a night and a day of this kind of discomfort before flying back. But then I was taken to the detention cell in downtown LA, where the discomfort became something worse.

Though my experience was far removed from the images of real torture and abuse at Abu Ghraib prison in Iraq, it was also, as one American friend put it, "conceptually related", at distant ends of the same continuum and dictated by a disregard for the humanity of those deemed "in the wrong". American bloggers and journalists would later see my experience as reflecting the current malaise in the country. Dennis Roddy wrote in the Pittsburgh Post-Gazette: "Our enemies are now more important to us than our friends ... Much of the obsession with homeland security seems to turn on the idea of the world infecting the US."

On a more practical level, this obsession, when practised with such extreme lack of intelligence (in both senses of the word), as in the case of my detention, must be misdirecting valuable money and manpower into fighting journalism rather than terrorism. Ordinary Americans, rather than the powers that be, are certainly able to make that distinction. According to an editor at the LA Times, there has been a "tremendous" response from readers to the reporting on my case, and I have received many emails expressing outrage and embarrassment. The novelist Jonathan Franzen wrote, "On behalf of the non-thuggish American majority, my sincere apologies."

These would have been comforting thoughts the following morning when I was driven back (in handcuffs, of course) to the communal detention room at LAX, and spent hours waiting, without food, while the guards munched enormous breakfasts and slurped hot morning drinks (detainees are not allowed tea or coffee). I incurred the wrath of the boss when I insisted on edible food. "I'm in charge in here. Do you know who you are? Do you know where you are? This isn't a hotel," he screamed.

"Why are you yelling?" I asked. "I'm just asking for some decent food. I'll pay for it myself." A Burger King fishburger never tasted so good. And it occurred to me that a hotel or transit lounge would have been a better place to keep travellers waiting to return home.

As documented by Reporters Without Borders and by the American Society of Newspaper Editors (Asne) in letters to Colin Powell and Tom Ridge, cases such as mine are part of a systemic policy of harassing media representatives from 27 friendly countries whose citizens - not journalists! - can travel to the US without a visa, for 90 days. According to Asne, this policy "could lead to a degradation of the atmosphere of mutual trust that has traditionally been extended professional journalists in these nations". Asne requested that the state department put pressure on customs and immigration to "repair the injustice that has been visited upon our colleagues". Someone must have listened, because the press office at the department of homeland security recently issued a memo announcing that, although the I-visa is still needed (and I've just received mine), new guidelines now give the "Port Directors leeway when it comes to allowing journalists to enter the US who are clearly no threat to our security". Well, fine, but doesn't that imply some journalists are a threat?

Maybe we are. During my surreal interlude at LAX, I told the officer taking my fingerprints that I would be writing about it all. "No doubt," he snorted. "And anything you'll write won't be the truth."