Aaron Swartz, a wizardly programmer who as a teenager helped develop code that delivered ever-changing web content to users and who later became a steadfast crusader to make that information freely available, was found dead Friday in his New York apartment.

Swartz, 26, hanged himself, according to a statement from his family.

At 14, Swartz helped create RSS, the nearly ubiquitous tool that allows users to subscribe to online information. He later became an internet folk hero, pushing to make many web files free and open to the public. But in July 2011, he was indicted on federal charges of gaining illegal access to JSTOR, a subscription-only service for distributing scientific and literary journals, and downloading 4.8 million articles and documents, nearly the entire library.

Charges in the case, including wire fraud and computer fraud, were pending at the time of Swartz’s death, carrying potential penalties of up to 35 years in prison and $1 million in fines.

“Aaron built surprising new things that changed the flow of information around the world,” said Susan Crawford, a professor at the Cardozo School of Law in New York who served in the Obama administration as a technology adviser. She called Swartz “a complicated prodigy” and said “graybeards approached him with awe.”

Michael Wolf said he would remember his nephew, who had written in the past about battling depression and suicidal thoughts, as a young man who “looked at the world, and had a certain logic in his brain, and the world didn’t necessarily fit in with that logic, and that was sometimes difficult.”

The Tech, a newspaper of the Massachusetts Institute of Technology, reported Swartz’s death early Saturday.

Swartz led an often itinerant life that included dropping out of Stanford, forming companies and organizations, and becoming a fellow at Harvard University’s Edmond J. Safra Center for Ethics.

He formed a company that merged with Reddit, the popular news and information site. He also co-founded Demand Progress, a group that promotes online campaigns on social justice issues – including a successful effort, with other groups, to oppose a Hollywood-backed Internet piracy bill.

But he also found trouble when he took part in efforts to release information to the public that he felt should be freely available. In 2008, he took on PACER, or Public Access to Court Electronic Records, the repository for federal judicial documents.

The database charges 10 cents a page for documents; activists like Carl Malamud, the founder of public.resource.org, have long argued that such documents should be free because they are produced at public expense. Joining Malamud’s efforts to make the documents public by posting legally obtained files to the internet for free access, Swartz wrote an elegant little program to download 20 million pages of documents from free library accounts, or roughly 20 percent of the enormous database.

The government abruptly shut down the free library program, and Malamud feared that legal trouble might follow even though he felt they had violated no laws. As he recalled in a newspaper account of the events, “I immediately saw the potential for overreaction by the courts.” He recalled telling Swartz: “You need to talk to a lawyer. I need to talk to a lawyer.”

Swartz recalled in a 2009 interview, “I had this vision of the feds crashing down the door, taking everything away.” He said he locked the deadbolt on his door, lay down on the bed for a while and then called his mother. The federal government investigated, but did not prosecute.

In 2011, however, Swartz went beyond that, according to a federal indictment. In an effort to provide free public access to JSTOR, he broke into computer networks at MIT by means that included gaining entry to a utility closet on campus and leaving a laptop that signed into the university network under a false account, federal officials said.

Swartz turned over his hard drives with 4.8 million documents, and JSTOR declined to pursue the case. But Carmen M. Ortiz, a U.S. attorney, pressed on, saying that “stealing is stealing, whether you use a computer command or a crowbar, and whether you take documents, data or dollars.”

Malamud said that while he did not approve of Swartz’s actions at MIT, “access to knowledge and access to justice have become all about access to money, and Aaron tried to change that. That should never have been considered a criminal activity.”

Swartz did not talk much about his impending trial, Quinn Norton, a close friend, said in an interview Saturday. But when he did, she said, it was clear that “it pushed him to exhaustion. It pushed him beyond.”

Recent years had been hard for Swartz, she said, and she characterized him “in turns tough and delicate.” He had “struggled with chronic, painful illness as well as depression,” she said, without specifying the nature of his illness, but was still hopeful “at least about the world.”

Cory Doctorow, a science fiction author and online activist, posted a tribute to Swartz on BoingBoing.net, a blog he co-edits. In an email, he called Swartz “uncompromising, principled, smart, flawed, loving, caring, and brilliant.”

“The world was a better place with him in it,” he said.

Swartz, he noted, had a habit of turning on those closest to him, saying that “Aaron held the world, his friends, and his mentors to an impossibly high standard – the same standard he set for himself.” He added, however, “It’s a testament to his friendship that no one ever seemed to hold it against him (except, maybe, himself).”

In 2007, Swartz wrote about his struggle with depression, distinguishing it from sadness. “Go outside and get some fresh air or cuddle with a loved one and you don’t feel any better, only more upset at being unable to feel the joy that everyone else seems to feel. Everything gets colored by the sadness.”

When the condition gets worse, he wrote, “you feel as if streaks of pain are running through your head, you thrash your body, you search for some escape but find none. And this is one of the more moderate forms.” Earlier that year, he gave a talk in which he described having had suicidal thoughts during a low period in his career.

Lawrence Lessig, the head of the Safra Center at Harvard, who worked for a time on behalf of Swartz’s legal defense, noted in an interview that the police in Cambridge, Mass., had arrested Swartz almost two years to the day before his suicide. That arrest led to the eventual federal indictment and financial ruin for Swartz, who had made money on the sale of Reddit to Conde Nast but had never tried to turn his intellect to making money.

“I can just imagine him thinking it was going to be a million-dollar defense,” Lessig said. “He didn’t have a million dollars.”