Until the moment the FBI burst through his door, it had been much like any other day for Barrett Brown.

The 31-year-old writer and activist, closely affiliated to the Anonymous hacking collective, had been joking around late at night in an internet webcam chat room with a few friends. But the conversation abruptly halted when Brown's video feed blacked out. Amid a flurry of commotion and cries of "get down," a troupe of armed agents surged into his apartment in Dallas, Texas, and handcuffed him face down on the floor.

Since that evening, on 12 September last year, Brown has been in a Texas jail awaiting a looming trial that could land him several decades behind bars. He stands accused of committing 17 offences in total, including aiding and abetting aggravated identity theft, making internet threats, and retaliation against a federal law enforcement officer. But it is no ordinary, open and shut case. It is a bizarre saga that involves a web of secrets, scandals, covert informants and some of the most widely publicised computer hacking conspiracies in recent history.

US authorities have made it clear in indictments lodged against Brown that they view him as a menace to society – an anti-government anarchist agitating for violent revolution. But supporters claim he is being subjected to heavy-handed prosecution, comparing his plight to that of Matthew Keys, the Reuters social media editor accused last week of conspiring with Anonymous, and Aaron Swartz, the prominent internet freedom activist who committed suicide in January while facing a host of controversial hacking charges. In reality, neither side is the full story.

Brown, just short of 6 feet tall, skinny with sandy brown hair, grew up in an affluent part of Dallas County, the son of a wealthy Texas real estate developer. He is a somewhat eccentric character – a college dropout firebrand with a history of drug addiction and a penchant for ranting, red wine and cigarettes.

Before he crossed paths with the FBI, Brown was a prolific writer who had contributed to publications including Vanity Fair, the Guardian, the Huffington Post and satirical news site the Onion. He had a short stint in politics as the director of communications for an atheist group called Enlighten the Vote, and he co-authored a well-received book mocking creationism, Flock of Dodos, which the Harvard law professor Alan Dershowitz compared to works by celebrated authors Thomas Paine and Mark Twain.

"I really just wanted to write humour and was absolutely on track to doing so until a couple events and thoughts in 2009," Brown told me in August last year, shortly before his arrest. What changed his trajectory was that he immersed himself in what he would sometimes jokingly term "this computer shit" – a strange and chaotic world of online activism.

There were a number of factors involved, each of them closely connected. It began when Brown hatched the idea for an internet thinktank he named Project PM, in 2009, dedicated to investigating private government contractors working in the secretive fields of cybersecurity, intelligence and surveillance. Then, in 2010, WikiLeaks published thousands of classified US government documents. And at around the same time Anonymous exploded onto the world stage, attacking the Church of Scientology and defending WikiLeaks by declaring cyberwar on payment processors like Paypal and Visa, which had blocked the whistleblower website's funding sources after pressure from US politicians.

Brown saw a conflation of interests between Project PM, WikiLeaks and Anonymous. He believed WikiLeaks was doing a "tremendous service to humanity" by releasing classified government information, and he was inspired by Anonymous, which he viewed as "unprecedented" because of the way it brought people on the internet together as a force for political change.

Before long, Brown had directly affiliated himself with Anonymous, and by early 2011 he was working alongside some its most skilled hackers as a sort of de facto press officer. He had no hacking ability, but instead put his flair for writing and rhetoric to use. He would send out missives to his media contacts and do televised interviews in which he would rail against murky government cybersecurity initiatives that he said Anonymous would expose.

Some within the diffuse community of Anonymous took an instant dislike to Brown, accusing him of being a paranoid egomaniac who was seeking fame and hogging the limelight. But he rarely gave his critics a second glance because, as far as he was concerned, he had more pertinent issues to deal with – on one occasion embroiling himself in a surreal public spat with a Mexican drug cartel over a kidnapped activist.

"We have hit upon things here that really do matter – that haven't been given due consideration," he would bark in his distinctive, rapid-fire baritone southern drawl. "The battlefield is the information flow."

Brown's interviews, some aired as "exclusives" on major US TV news networks like NBC, grabbed attention. He viewed himself as engaged in what he would refer to as "information operations," almost like a military propaganda campaign. Hackers would sometimes obtain data and then pass it on to him. He would spend days and nights hunkered down in his small uptown Dallas apartment pouring through troves of hacked documents, writing blog posts about US government intelligence contractors and their "misplaced power" while working to garner wider media coverage.

When servers belonging to the American security thinktank Stratfor were infiltrated by the hackers in December 2011, for instance, Brown alerted reporters across the world. He told the Times that millions of stolen emails, later published by WikiLeaks, could prove to be "the smoking gun for a number of crimes of extraordinary importance". It was mostly hyperbole, of course, but he was a skilled operator. He knew how to get headlines, especially headlines that would rile his adversaries.

By becoming a public advocate for hackers implicated in major computer crimes, however, Brown was in extremely shaky legal territory. He had developed a close relationship with an Anonymous splinter group called AntiSec – a volatile, militant outfit that had evolved out of LulzSec, another Anonymous offshoot which took credit for a series of prominent attacks on government websites and multinational corporations over a 50-day rampage in the summer of 2011.

AntiSec became highly active toward the end of 2011, hacking Stratfor and then later a Virginia-based law firm involved in defending a US marine who had played a key role in a massacre of civilians during the Iraq war. The group dumped thousands of Stratfor customers' credit card numbers online and posted a large trove of emails obtained from the law firm, collaterally exposing personal details about victims of sexual assault in the process.

It appeared that the hackers were becoming increasingly callous and equally careless, veering from the "vigilantes for good" image they liked to project of themselves.

Brown said that the credit card leak was a "public relations blunder" that had caused internal conflict between the hackers. One party had been "blindsided" by the data dump, according to Brown, and one of the team quit the group and "went dark" because of it.

"I wasn't informed of the leak or the nature of the leak," he told me at the time. "I do defend them for it and I will take responsibility for defending them. But if I had my way it would have been done differently. I have no... they don't need me, basically, so they don't ask my opinion."

But by then it was too late: Brown's relationship with AntiSec had pinned a law enforcement target on his back. A few months after the hack on Stratfor, he was raided for the first time by the FBI. He was not arrested, but some of his property, including his laptop computer, was confiscated as evidence.

On the same day, 6 March 2012, an explosive Fox News story outed a core member of both AntiSec and LulzSec as an FBI informant. "Sabu," real name Hector Monsegur, 29, had been "turned" nine months earlier by the authorities after being traced to his New York apartment.

In order to escape jail, Monsegur, a notorious loudmouth elite hacker who was considered a ringleader of the groups, had been covertly cooperating with the FBI to help build cases against, and track down, his former partners. It was an extraordinary development that shook the hacking community and made front page news internationally.

Prosecutors, likely assisted at least in part by evidence gleaned by Monsegur, have since accused Brown of aiding and abetting the transfer of the credit card numbers obtained from Statfor's servers in a case of aggravated identity theft. The hackers used the credit cards to fraudulently donate hundreds of thousands of dollars to charities including the Red Cross and Save the Children.

Brown, who denies all of the charges against him, is also accused of a separate fraud-related offence that carries up to 15 years imprisonment for copying and pasting a hyperlink in a chat room to a file that allegedly included within it some 5,000 Stratfor credit card details. This has caused an outcry among some activists, with secret-spilling website Cryptome – which published the same link Brown is accused of sharing – posting a statement likening the charge to "official chilling of free speech online" and criticising "over-reaching indictments."

The spiralling debacle eventually took its toll on Brown. The FBI seizure of his property and the revelation about Monsegur, whom he angrily branded a "degenerate pussy traitor," seemed pivotal.

When I spoke to him earlier in 2011 he had appeared optimistic – as if he felt he was riding the crest of an unstoppable wave. He would talk enthusiastically about "spiritual change" taking place due to revolutions sweeping the Arab world, and explain how young Anonymous hackers he knew had assisted activists in the Middle East by providing them with tools to counter government surveillance and tracking. But by spring 2012, his mindset seemed to alter, his mood darker and at times almost anguished.

"We're losing hope in the idea of trying to convince the American people to pay attention to something that matters," he lamented in April, speaking on the phone from Dallas. "To some extent we are all the enemy, all of us have failed."

Brown was frustrated that mainstream media outlets were not covering stories he felt deserved attention. He would complain that reporters would often approach him and ask about the personalities of some of the more prominent hackers, like Monsegur, but ignore the deeper issues about governments and private contractors contained in documents that had been hacked.

Complicating matters further, as a recovering heroin addict, Brown was taking Suboxone, a prescription drug used to treat opiate withdrawal. This was having an impact on his health, perhaps amplified by the cyclone of drama engulfing him. One day in August, he told me he had broken down in tears. "All of it gets to be too much," he wrote in an email.

Three weeks later, Brown would be in jail. He had posted online a series of videos in which he appeared to issue threats directed at a named FBI agent, whom he accused of harassing his mother, and demanded that his previously seized property be returned. In the videos he looked frazzled, pale and on edge. He concluded with a lengthy tirade, saying he feared drug cartel "assassin squads" were out to get him and warning government officials not to come near his apartment.

"I will shoot all of them and kill them if they come," he said, looking blankly straight into the camera. "It was pretty obvious I was going to be dead before I was forty or so – so I wouldn't mind going out with two FBI sidearms like a fucking Egyptian Pharaoh."

Within hours of the video appearing, agents charged through his door and pinned him to the floor. For the FBI, it was clearly the final straw. Brown had moved from publishing long blog screeds blasting shady security firms to making violent threats. Hyperbole or not, a line had been crossed. His time was up.

When the moment finally came, Brown can't have been too surprised. He suspected that one day he was going to end up carted off to a dingy jail cell, he just didn't know exactly when or in what circumstances. He had accepted his fate fairly soon after becoming involved with Anonymous.

"I'll probably be charged or indicted," he told me during one interview in early 2012. "I just hope that a trial will bring more media attention to the issues that brought me here in the first place."

Brown is due to face two separate trials, the first of which is scheduled to begin on 3 September.

Last I heard from him he was doing all right.

"How's everything?" he wrote in short message. "I seem to be in prison."