A federal judge on Thursday ordered the man charged with this week's mass shooting in a New York subway to remain in custody and undergo a psychiatric exam as he awaits trial for one of the most violent attacks on the city's mass transit system.

Frank James, 62, making his initial court appearance a day after his arrest in lower Manhattan, is accused of injuring 30 people by setting off smoke bombs and spraying the inside of a subway car with gunfire during Tuesday morning's rush-hour commute in Brooklyn.

James was represented by two public defenders as he was formally presented with a criminal complaint charging him with a single count of committing a terrorist or other violent attack against a mass transportation system - a felony carrying a maximum sentence of life in prison.

"The defendant terrifyingly opened fire on passengers in a crowded subway train, interrupting their morning commute in a way this city hasn't seen in more than 20 years," Assistant U.S. Attorney Sara Winik told the federal court in Brooklyn, in an apparent reference to the attacks of Sept. 11, 2001.

Arguing that James poses a "severe and ongoing danger" to the public if released, prosecutors said in a court filing that he carried out "a premeditated violent attack on unsuspecting commuters trapped underground with their assailant in a subway car."

The mass shooting followed a string of violent crimes that had already unnerved riders of one of the largest subway systems in the world, including instances of commuters being pushed onto subway tracks from station platforms.

James, dressed in beige jail clothes and wearing a blue surgical mask, spoke only briefly to say he understood the charges.

U.S. Magistrate Judge Roanne Mann ordered James to be held at the Metropolitan Detention Center in Brooklyn, the main jail for defendants awaiting federal trial in New York City, and ordered the psychiatric evaluation requested by his lawyers.

The defense stressed the examination was not aimed at determining James' competence to face trial but to establish the state of his mental health for any treatment he needs.

Authorities have offered no possible motive for the attack.

VIDEO RANTS UNDER SCRUTINY

Investigators have said they are examining lengthy videos James apparently recorded and posted to YouTube, which included bigoted rants and comments on New York City's mayor, homelessness and the subway system. The YouTube account was taken down Wednesday for violating the online video platform's "community guidelines," the company said.

James was arrested without incident on Wednesday afternoon on a street in Manhattan's East Village neighborhood, about 5 miles (8 km) from the scene of Tuesday's attack, capping a 30-hour manhunt for the lone suspect. His lawyers told reporters after the hearing that James himself had called the New York Police Department's tipline to turn himself in after seeing his photograph in the news.

"He called 'Crime Stoppers' to help," Mia Eisner-Grynberg, a lawyer from the Federal Defenders of New York, told reporters. "He told them where he was." Earlier news reports said James placed the call from a McDonald's restaurant in the East Village. He was taken into custody a short distance away.

Eisner-Grynberg called the attack a tragedy, which unfolded as the Manhattan-bound N train was pulling into the 36th Street subway station in Brooklyn's Sunset Park community.

Police said 10 people were shot, five of them hospitalized in critical but stable condition. About 20 others were injured by the smoke canisters the attacker set off before shooting or in the stampede of terrified passengers pouring out of the subway car onto the platform, according to prosecutors. All were expected to survive.

The attacker apparently followed the panicked passengers into another train and rode it one stop toward Manhattan, investigators said.

Surveillance video shows James emerging one station north at about 14 minutes after the shooting. An image included in the complaint shows him in a dark outfit, without the fluorescent orange jacket and yellow helmet worn earlier.

Video footage from the scene may prove to be less extensive than it should. The New York Police Department (NYPD) issued a statement on Wednesday saying security cameras were out of service at the 36th Street station and two other subway stops on Tuesday.

Investigators said they established James as a suspect after finding on the platform a credit card in his name and keys to a U-Haul van he had rented and left parked several blocks away.

Authorities at the scene also recovered the semi-automatic handgun used in the attack, along with three extended-ammunition magazines, a torch, a hatchet, a bag of fireworks and a container of gasoline, according to police and court documents.

James is a Bronx native with recent addresses in Philadelphia and Milwaukee. He had nine prior arrests in New York and three in New Jersey, according to the New York Police Department. 

In addition to items found at the subway station, searches of James' apartment and a storage locker in Philadelphia uncovered more handgun and rifle magazines, ammunition, a Taser and a pistol barrel attachment for a silencer, the FBI said.