Updated

The suspect in a shooting that left a U.S. congresswoman wounded pleaded guilty Tuesday to going on the rampage that killed six other people. The plea spares Jared Lee Loughner the death penalty in an attack that gained worldwide attention.

The plea came soon after a federal judge had found that months of forcibly medicating Loughner to treat his schizophrenia had made the 23-year-old college dropout competent to understand the gravity of the charges against him and assist in his defense.

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.

Burns noted Loughner's reaction to the prison guard comment when explaining his decision to declare him competent. He said Loughner was "tracking" the day's proceedings well and appeared to be assisting his attorneys in his defense, a break from the past.

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 pleaded guilty to 19 counts, including attempted assassination of a member of Congress, murder and attempted murder of federal employees, and causing death and injury at a federally provided activity. As part of the agreement, the federal government dropped 30 other counts.

Loughner faces life in prison without the possibility of parole.

The prosecution and defense seemed eager to seal the agreement, a departure from previous marathon hearings. Judy Clarke, Loughner's lead attorney, gently pointed Loughner through a copy of the plea agreement on the table in front of him as the judge went through it. She declined to ask the psychologist any questions.

The plea agreement calls for a sentence of seven consecutive life terms followed by 140 years in prison, according to federal officials. Loughner, who will be sentenced Nov. 15, is ineligible for parole.

John Leonardo, the U.S. attorney for Arizona, called the agreement a "just and appropriate resolution."

"I hope that today's resolution of this case will help the victims, their families, and the entire Tucson community take another step forward in the process of healing and recovering from this sad and tragic event," he said.

Gabrielle Giffords, the congresswoman who was the intended target, continues to recover from the January 2011 shooting. She has left her Congress post.

Among the dead were Arizona's chief federal judge and a Giffords' aide. Twelve other people aside from Giffords were wounded.

The outcome was welcomed by some victims, including Giffords, 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."

Ron Barber, a former Giffords staffer who was wounded in the attack and later won election to her seat after she stepped down, said he hoped the plea will help the victims and their families "move forward and continue our healing process."

"I truly believe that justice was done today," he said after the hearing. "It is important to me that this individual never again is in a position in which he can cause harm to anyone else."

Susan Hileman, who accompanied slain 9-year-old Christina-Taylor Green to the gathering outside a supermarket and was wounded in the attack, said nothing would return her life to what it was before the shooting.

"This is so sad -- a 23-year-old who's going to spend the rest of his life in a box. I feel empty. What I want, I can't have," she said, adding that she was relieved the case ended. Still, "it's like a Band-Aid that keeps getting ripped off."

Christina Pietz, the court-appointed psychologist, testified that Loughner appeared to be a normal child and average student until he was 16, when a girlfriend broke up with him and a friend's father died. He was diagnosed with depression at the time and landed at an alternative education program at Pima Community College his senior year after he showed up drunk for school one day.

He was enrolled at the Tucson college until September 2010, alarming his parents and friends with his increasingly erratic behavior, Pietz said. He became obsessed with the U.S. Constitution, wrote jumbled words on the chalkboard and a final exam, and yelled incoherently in class.

Loughner's parents, Randy and Ann Loughner, told Pietz that their son once asked them if they heard voices. They worried that he would take his life.

Pietz recounted several turning points in Loughner's recovery in prison: regular exercise; counseling sessions with three other inmates; and prison jobs rolling towels, T-shirts and socks, and stamping envelopes. He has been forcibly medicated for more than a year after being diagnosed with schizophrenia.

"He loves his jobs," she said.

Pietz said Loughner's refusal to acknowledge that Giffords survived and his insistence that a surveillance video of the shooting was a fake made her reluctant to declare him competent. Over time, he acknowledged that Giffords survived the gunshot wound to her head, considering it a failure on his part.

"He's disappointed, this is another failure in his life, he set out to do this," said Pietz, describing his thinking as the realization set in that congresswoman survived.

Giffords has undergone intensive therapy and made dramatic progress recovering from her brain injury, yet her movements and speech are still halting.

For prosecutors, the plea avoids a potentially lengthy and costly trial and appeal, and locks up the defendant for life.

Clarke managed to avoid the death penalty for other high-profile clients such as "Unabomber" Ted Kaczynski and Eric Rudolph, who bombed abortion clinics in the late 1990s and Atlanta's Olympic park in 1996.

One uncertainty hanging over the case is whether Loughner will face state charges. The plea agreement to the federal charges makes no mention of that possibility.

Pima County's top prosecutor said last year that she may file state charges in the case that could carry the death penalty. In an agreement with federal prosecutors, County Attorney Barbara LaWall agreed that the federal prosecution would take place before she could bring charges.

LaWall has been unavailable in recent days, and officials in her office have repeatedly declined to comment, saying the office did not have an active prosecution against Loughner.

A state prosecution after a successful federal one would not be unprecedented. Oklahoma City bombing conspirator Terry Nichols avoided the death penalty on federal charges after a 1997 trial and was given a life sentence. State prosecutors then tried him again, but a state jury also declined to sentence him to death.

The Associated Press contributed to this report