The disturbed gunman Jared Lee Loughner pleaded guilty Tuesday to carrying out a deadly Arizona mass shooting in January 2011, an attack where he failed to assassinate US Congresswoman Gabrielle Giffords.
Six people were killed in the shooting and 13 were injured, including the congresswoman.
By pleading guilty, Loughner, 23, will avoid the death penalty but he still faces a life sentence without the possibility of parole, the prosecution explained during the hearing at a federal court in Tucson.
He also waived all right to appeal.
Dressed in a tan prison jumpsuit, his hair cut short, Loughner appeared calm and showed little emotion as he answered the judge's questions.
Asked if it was true he had approached Giffords intending to kill her, Loughner replied: "Yes, it is."
His lawyer, Judy Clark, said her client had agreed to plead guilty "knowingly, voluntarily, and intelligently."
A few minutes earlier, Federal Judge Larry Burns had declared the defendant mentally competent to understand and admit to the charges against him.
Loughner has been receiving psychiatric treatment for more than a year for schizophrenia on the court's orders. He had previously pleaded not guilty, but Judge Burns decided at the time he was not competent to stand trial.
Government psychologist Christina Peitz testified on Tuesday that Loughner is psychotic but not deluded, and said the gunman had expressed disappointment that he was a "failure" for not having killed Giffords and others.
Pietz said his condition had improved markedly since he was ordered into treatment in 2011, and added that his mental state would not prevent him from participating in his own defense.
Loughner opened fire on January 8, 2011, outside a Tucson supermarket where Giffords, a Democrat, was meeting with constituents.
Among the six dead were a federal judge, a nine-year-old girl and a member of the congresswoman's staff.
Suzi Hileman, 59, who was wounded in the shooting, had brought the nine-year-old girl, her neighbor Christina Taylor Green, to the event.
"I'm glad he's aware of what he's done," she told reporters at the court, referring to Loughner. "But it changes nothing."
She said more should have been done to prevent Loughner from getting his hands on the weapons he used.
"This just should never have happened," she said.
John Leonardo, the US attorney and one of the chief prosecutors in the case, said "we feel this is a certain, just, and appropriate resolution of this case."
In January, 41-year-old Giffords -- who had been seen as a rising star in the Democratic Party -- resigned from congress to focus on her remarkable but continuing recovery.
Loughner's change of plea came as the United States reels from two more recent mass shootings.
In Oak Creek, Wisconsin, Wade Michael Page, 40, burst into a Sikh temple on Sunday with a 9mm handgun and several clips of ammunition, and shot dead six unarmed citizens at a worship service.
That shooting came just two weeks after 12 people were gunned down at a screening of the new Batman movie "The Dark Knight Rises," in Aurora, Colorado.