McCarthy Hall, a dormitory where a student made ricin, is seen on the Georgetown University campus on March 20. (Katherine Frey/The Washington Post)

When his roommate went away for a long weekend, the Georgetown University sophomore told authorities, he turned their dorm room at 615 McCarthy Hall into an impromptu laboratory to create one of the world’s most deadly poisons — an idea he gleaned from the hit TV show “Breaking Bad.”

Daniel Milzman, who friends said has a sharp scientific mind, spent days carefully tinkering with castor beans and chemicals, finally producing a lethal amount of a toxin that is seven times as powerful as cobra venom: ricin. The poison has been manufactured by terrorists and can kill with just a small amount of contact, but it rarely has been used.

On March 17, Milzman, 19, tossed a plastic bag filled with the gray powdery substance at the feet of a friend, saying that part of him wanted to be dared to use it and that the other half did not, court documents show.

Federal prosecutors and Milzman’s attorneys sparred over the question of his intentions at a detention hearing Tuesday in U.S. District Court. Assistant U.S. Attorney Maia Miller argued that the pre-med student should be held without bond, saying Milzman had “intended to cause harm in the worst way” by using the ricin to poison someone or himself.

Danny Onorato, Milzman’s attorney, said his client was suffering from depression.

“He was tortured. He was having a hard time in his life. He was a scared 19-year-old kid,” Onorato said. The ricin was “not intended for anyone other than himself.”

Magistrate Judge John M. Facciola agreed, ordering Milzman released to an in-patient psychiatric program at Sibley Memorial Hospital.

The hearing and a 13-page document filed by prosecutors Tuesday offered fresh details about the events of March 17 and 18 that forced the evacuation of McCarthy Hall and required the school to hire a hazmat team to clean Room 615. Friends said Milzman was outwardly jovial and driven, but the documents show a young man beset by turmoil and harboring a secret.

“He kept himself so collected,” said Joseph Laposata, a friend and sophomore at Georgetown. “I never saw him lash out in a fit of rage. I guess he bottled it up and the force of it all exploded.”

About 8:30 p.m. on March 17, Milzman sent a text to a friend and former love interest at Georgetown, according to court records and Milzman’s attorney. Could they meet?

During the meeting, Milzman told the man that he was anxious and felt unfulfilled by school and his personal relationships, court documents say. Milzman began crying and said he had started to engage in “risky behavior,” according to court records.

Milzman pulled a plastic bag sealed with hockey tape from his backpack and threw it on the floor in front of the friend, telling him that it was ricin, court records say. Milzman said he manufactured it over four days, while his roommate was on a school break. He said he felt as if it was the first thing he had done well in a while.

The friend asked Milzman whether he was suicidal or a threat to others. Court records say Milzman denied being suicidal but said he was “definitely a threat to someone.”

The man contacted Georgetown University counseling services, and they, in turn, alerted police. Milzman told officers who arrived at the scene how he made the ricin, bought the precursor materials at the Home Depot and a plant store, and disposed of the leftover materials in a trash bin behind his parents’ D.C. home.

Prosecutors argued Tuesday that Milzman made the ricin less than two months after posting threatening Facebook messages about another Georgetown student. Friends said Milzman had a falling out with the man, but they declined to discuss specifics.

Milzman wrote in one post obtained by The Washington Post that he would say goodbye to the fellow student only after the student jumped off the Key Bridge.

“I’ll be the one at the bottom, waving, saying ‘do a flip,’ ” Milzman wrote.

The messages prompted a graduate of the university to report him to the school administration.

Milzman’s decision to reveal to his friend that he had created ricin, his attorney said, was a “cry for help. He knew this person would take action.” Onorato said the Facebook comments were the result of a spat that was a “two-way street” and that involved a “much more complicated set of facts.”

Milzman’s arrest brought a swift end to what seemed to be a promising start. He had graduated from Bethesda’s Walt Whitman High School, where he was a National Merit semifinalist and a member of the Quiz Bowl and hockey teams.

Students remember that he raised money for leukemia research and launched several unsuccessful runs for president of the student government association that were punctuated by humorous speeches. One student said Milzman had a “glowing” personality.

At Georgetown, he was a founder of a Quiz Bowl chapter and a member of the Secular Student Alliance. He co-authored articles with his father, David Milzman, who is the research director at the Department of Emergency Medicine at MedStar Georgetown University Hospital.

“He was driven and really organized,” said Lilli Seabol, a Georgetown freshman who was on the Quiz Bowl team.

Laposata, the friend, said Milzman was lightning-quick when it came to answering science questions. He “knew his stuff,” Laposata said. He also said Milzman could name every single episode of “Breaking Bad” and described it as his favorite show.

That publicly successful persona clashed with the private Milzman. He told authorities after his arrest that he has suffered from depression since the 10th or 11th grade, court papers say.

He told investigators that he created the ricin as a stealthy way to commit suicide: If he grew sick and had flulike symptoms, he said, no one would realize that he had taken his own life. Milzman said he found the ricin formula by browsing the Web on his iPhone. In contrast to the conversation reported by his friend, he told authorities that he was adamant that no one else be exposed to the toxin.

In rejecting the government’s detention request, the judge said he was persuaded by a psychiatric evaluation that detailed Milzman’s four-year struggle with depression and suggested he was suicidal. Facciola called the evidence that Milzman was a threat “ambiguous.”

The judge gave prosecutors one day to decide whether to appeal his decision. No additional hearing dates have been set.

Graham Schiff, 22, who knew Milzman at Whitman, said the case is perplexing. He said Milzman had a comprehensive knowledge of politics that belied his age. He had a solid family and a good upbringing.

“He was very intelligent for his age and had an independent streak,” Schiff said. “He seemed a bit quirky at times, but he definitely impressed me.”

Onorato, Milzman’s attorney, said in court that Milzman and his family take seriously the charges, which carry prison time of up to 10 years, and that they sought out the psychiatric program at Sibley.

“He wants to make sure he does well in the future,” the lawyer said.