Loughner's plea spares him the death penalty and came soon after a federal judge found that months of forcibly medicating him to treat his schizophrenia had made the 23-year-old college dropout competent.
At one point, Judge Larry A. Burns asked Loughner if he understood the charges against him and what the government would need to convict him.
"Yes, I understand," Loughner replied.
The judge said that Loughner was a different person and that he is able to help his lawyers in his defense. Burns said that observing Loughner in the court left "no question that he understands what's happening today."
Loughner faces life in prison without the possibility of parole.
The outcome was welcomed by some victims, including Giffords herself, as a way to avoid a lengthy, possibly traumatic trial and years of legal wrangling over a death sentence.
"The pain and loss caused by the events of Jan. 8, 2011, are incalculable," Giffords said in a joint statement with her husband, Mark Kelly. "Avoiding a trial will allow us -- and we hope the whole Southern Arizona community -- to continue with our recovery."
Experts had concluded that Loughner suffers from schizophrenia, and officials at a federal prison have forcibly medicated him with psychotropic drugs for more than a year.
Court-appointed pyschologist Christina Pietz testified for an hour about how she believes Loughner became competent. Loughner listened calmly without expression. His arms were crossed over his stomach, lurched slightly forward and looking straight at Pietz.
At one point, he smiled and nodded when psychologist mentioned he had a special bond with one of the prison guards.
A plea agreement offers something for both sides, said Quin Denvir, a California defense attorney who has worked with Loughner attorney Judy Clarke on the case against unabomber Ted Kaczynski.
Prosecutors would avoid a potentially lengthy and costly trial and appeal, knowing that the defendant will be locked up for life. Clarke managed to avoid the death penalty for other high-profile clients such as Kaczynski and Eric Rudolph, who bombed abortion clinics in the late 1990s and Atlanta's Olympic park in 1996.
The top prosecutor in southern Arizona's Pima County said last year that she may file state charges in the case that could carry the death penalty. An official in the prosecutor's office, Amelia Craig Cramer, declined to comment, saying the office did not have an active prosecution against Loughner.
Denvir said it was possible that the plea agreement calls for the state to avoid pursuing criminal charges against Loughner, though that's not a given.
"Ideally (as a defense attorney) you'd like to have it resolved all at once, but sometimes you have to take one at a time," he said.
The decision to spare Loughner a federal death sentence makes sense, said Dale Baich, a federal public defender in Phoenix who handles capital case appeals and isn't involved in the case.
"As time went on and there were numerous evaluations, I think everybody had a better understanding of Mr. Loughner's mental illness." Baich said.
He added: "It appears that he will need to be treated for the rest of his life in order to remain competent."