PORTLAND, Maine — A federal judge denied bail Wednesday to Casey James Fury, the man accused of setting a fire to the USS Miami in May, causing over $400 million in damage.

Despite a recommendation for bail conditions from the probation office, U.S. Magistrate Judge John H. Rich denied bail to Fury after ruling no combination of bail conditions could ensure he would not be a danger to the community.

Fury, 24, did not react as the judge issued the ruling, but some of the family members present in court buried their faces in their hands and leaned on each other for support.

Fury was mostly silent throughout the hearing, staring ahead during the proceedings at the U.S. District Court. As he was led from the courtroom after the ruling Fury kept his eyes to the ground and did not acknowledge his father and other family members present.

He faces two charges of arson in connection with the May 23 fire at the Portsmouth Naval Shipyard, which left seven people injured, and another fire set June 16 in the nuclear submarine’s dry dock area, which was quickly extinguished.

According to an affidavit filed by the Naval Criminal Investigative Service, Fury confessed to setting the two fires, blaming a struggle with anxiety and wishing to leave work early. Fury has also confessed to pulling a fire alarm June 19 in order to get off work.

The affidavit describes a confession, captured on video, in which Fury walked investigators through a reenactment of his actions. They conducted the reenactment on the USS Pasadena, a submarine similar to the USS Miami, as well as on the heavily damaged Miami.

The bail decision came after a hearing that included testimony from the lead investigator on the case, a navy fireman injured in the May 23 fire and Fury’s father and stepmother.

Navy Lt. Richard McMunn, who described the May 23 fire on the USS Miami as the worst he has ever encountered, was one of the first to respond. He described descending into an infernal atmosphere, his vision obscured by thick black smoke.

“It felt like climbing down the chimney of a furnace,” McMunn said.

After climbing down a ladder, McMunn said he shifted his weight and suddenly fell five or six feet, suffering six rib fractures and badly injuring his knee.

“After crawling five or six feet, I realized I was too injured to carry on,” McMunn said in his testimony. “The burden of my decision to retreat weighs on me to this day.”

McMunn asked that the court deny bail to Fury and remand him to detention. He said Fury did not seem to grasp the consequences of his actions, which McMunn said were “massive and cannot be measured.”

The testimony given Wednesday painted a picture of Fury as a troubled young man, struggling with anxiety, depression and insomnia. He has a brief criminal record, with a conviction for operating under the influence in New Hampshire in 2009 and an arrest for the same crime on June 14, two days before the second fire.

Fury checked into an inpatient mental health facility June 21 and stayed until June 23.

Fury’s father and stepmother, who testified they would be willing and able to supervise the defendant should he be released on bail, said they knew of his anxiety but denied knowledge of any problems with drugs or alcohol.

Because Fury’s father, James Fury, works full time, the role of third-party bail supervisor would have fallen to his stepmother, Margaret Fury, who held back tears as she answered questions from the judge, the defense attorney and Assistant U.S. Attorney Darcie McElwee. She said she would be willing to report any violations of his bail conditions, even if that meant he would return to jail.

After the hearing, Fury’s family members declined to comment on the case.

The question of bail rested on whether Fury would pose a danger to the community should he be released.

An investigation by the probation office found that Fury would be able to be safely released under the condition he have no access to unlawful drugs, alcohol or firearms. But McElwee strenuously disagreed with the report, dismissing the recommendations as “absurd” and neither appropriate nor helpful to the court.

McElwee said it was extremely rare for the recommendations of the prosecution and the probation office to differ.

Fury’s public defender, David Beneman, argued that much of the defendant’s alleged actions had stemmed from an escalating struggle with anxiety, and that in the month since the most recent fire, Fury was doing better on a new combination of drugs.

But in his decision, Rich said the court worried that Fury’s anxiety would be even higher as he awaits charges that could land him in prison for life.

McElwee argued Fury was especially dangerous because he allegedly set the June 16 fire even after seeing the massive repercussions of the May 23 fire.

“What kind of person knows all that and sets another fire so he can leave early,” McElwee said. “He shows a lack of judgment and concern for anyone on the planet other than himself.”

The Senate Defense Appropriations Subcommittee approved a 2013 defense funding bill Monday, which includes $150 million allocated to repairs on the USS Miami. The bill, which Sen. Susan Collins supported as a member of both the Senate Appropriations Committee and the Senate Armed Services Committee, is scheduled to be considered by the full Appropriations Committee Thursday.