A federal judge ruled Wednesday that shooting suspect Jared Lee Loughner is mentally unfit to stand trial for the Jan. 8 rampage in Tucson that wounded Rep. Gabrielle Giffords and killed six, citing expert testimony that Loughner is schizophrenic and shows a paranoid distrust of his own defense attorneys.

Facing an agitated Loughner in a Phoenix courtroom, U.S. District Judge Larry A. Burns remanded him to a federal facility in Springfield, Mo., where he will receive treatment aimed at restoring his competency. The judge ordered that Loughner be treated for up to four months, and if he is then deemed to be competent, the case against him could resume. If not, he could remain in treatment.

Federal prosecutors expressed confidence that Loughner eventually will be tried, but the ruling nevertheless introduced the possibility of indefinite delays in a case that has been closely watched by millions of Americans. Since the shooting, which also wounded 12 others, Giffords’s recovery has been chronicled by the media and prosecutors have gradually laid out the evidence they have compiled against Loughner.

Giffords (D-Ariz.), who was shot above her left eye, remains in a Houston medical center, where last week surgeons repaired a section of her skull with a ceramic implant. Just days before, she witnessed her husband, astronaut Mark Kelly, ascend into space aboard the space shuttle Endeavour.

Entering Wednesday’s hearing, Loughner, wearing a khaki prison suit, could be heard mumbling that the proceedings were “treasonous,” according to a witness.

Also, the Associated Press reported that Loughner said what sounded like “Thank you for the freak show. She died in front of me” before being escorted from the courtroom.

Loughner reportedly watched the end of the hearing on closed-circuit television after the judge gave him the option of restraining his outbursts or leaving the courtroom.

A spokesman for U.S. Attorney Dennis K. Burke, who is prosecuting the case, predicted that Loughner would be successfully medicated — willingly or forcibly — and then stand trial.

“We believe that Jared Loughner can be restored to competency through proper medication, and we’re pursuing that course,” Robbie Sherwood said in a telephone interview.

“This practice is common,” he said, adding that in “the vast majority of cases where defendants are declared not competent, they have been restored and go on to proceed with the cases.”

A call seeking comment from Loughner’s defense team at the Phoenix federal public defender’s office was not returned Wednesday.

Some legal experts disputed Sherwood’s contention and cautioned that restoring the mental capacity of schizophrenic defendants can take years.

Joseph diGenova, a former U.S. attorney in the District, pointed to the case of Eugene Weston Jr., who fatally shot two federal officers at the U.S. Capitol in 1998. Weston, found to be a paranoid schizophrenic, remains in a mental institution and has not gone on trial.

DiGenova, who helped prosecute presidential shooter John Hinckley Jr., said that in Loughner’s case, “whether psychotropic medication can get him to a balanced competence so that he can assist his lawyer and understand the nature of the case against him remains to be seen. . . . It’s not inconceivable that he would be in a mental institution for many years.”

At least two of the shooting victims — Giffords aide Pam Simon and retired Army Col. Bill Badger — were in the courtroom Wednesday. Sherwood said that they, along with relatives of other victims who were present, were briefed by the U.S. attorney’s office before and after the hearing.

“None of this is going to bring our son back,” said Ross Zimmerman, father of Giffords staffer Gabe Zimmerman, who died in the shooting. “We don’t have any animosity toward the poor kid. . . . Punishment isn’t part of our thought process.”

Other supporters of the victims said they are disturbed that the ruling will keep the spotlight on Loughner.

“I can’t say I’m shocked that someone would determine that he’s nuts,” said Michael McNulty, Giffords’s campaign chairman, who visited her in the hospital this month.

The judge’s ruling came after he reviewed the findings of two court-appointed mental-health professionals who had examined Loughner during his five months at the federal facility in Springfield.

Psychologist Christina Pietz and psychiatrist Matthew Carroll agreed that Loughner’s behavior met the standard of mental incompetence.

Sherwood stressed that Loughner will “stay at the Bureau of Prisons indefinitely if he is deemed a danger to the public or himself. And we’ve made a pretty good argument for that. If anywhere down the line his condition improves, if he snaps out of it, the charges will be reinstated.”

Loughner will be treated by doctors, who likely will prescribe medication to treat psychosis. If he refuses the drugs, the court could petition Burns to order forcible treatment, such as injections, experts said.

John Zwerling, a defense lawyer in Alexandria who is not involved in the case, said that such a scenario could raise complicated legal questions.

“There have been cases where people on death row were deemed so psychotic that they do not know what is happening,” Zwerling said. “The question was, would the court order that he be forcibly given medication so that he is sane enough that they could kill him? And then what are doctors ethically able to do?”

In the months and years before the shooting, Loughner exhibited delusional behavior that alarmed those who knew him, according to records and interviews.

Last week, Pima Community College, which Loughner attended, released a trove of documents after a judge granted a public-records request by the Arizona Republic. The 255 pages included e-mails Loughner sent to teachers, complaining about his grades — and notes from teachers who had grown increasingly concerned about his behavior.

They worried that he might have weapons, the documents show.

One student complained that Loughner put a small knife on his desk during class, prompting her to send an e-mail to the professor.

Another e-mail shows that the administration asked campus police to look into Loughner’s background.

At one point, the school appears to have contacted the Bureau of Alcohol, Tobacco, Firearms and Explosives to find out whether he had a gun.

The college kicked him out after he allegedly posted a YouTube video showing him wandering the campus and at one point stating, “this is my genocide school.”

Staff researcher Magda Jean-Louis contributed to this report.