TUCSON, Ariz. — Jared Lee Loughner agreed Tuesday to spend the rest of his life in prison, accepting that he went on a deadly shooting rampage at an Arizona political gathering and avoiding the prospect of a trial that might have brought him the death penalty.

His plea came after a federal judge found that months of psychiatric treatment made Loughner able to understand charges that he killed six people and wounded 13 others, including his intended target, then-Rep. Gabrielle Giffords.

Loughner appeared relaxed and focused throughout the two-hour hearing, much of it devoted to a court-appointed psychologist's account of his normal childhood, his teenage depression, his descent into schizophrenia as a young adult and his gradual recovery in prison to the point that she felt he was competent to face charges.

The psychologist and judge did most of the talking, as Loughner looked at them intently and leaned slightly forward with no expression, his arms crossed over his chest. He appeared to show emotion only once – smiling and nodding when the psychologist, Christina Pietz, reported that he formed a special bond with one of the guards at the Springfield, Mo., prison where he has been held.

U.S. District Judge Larry 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.

"He's a different person in his appearance and his affect than the first time I laid eyes on him," Burns said.

During the hearing, Loughner didn't exchange words with his attorneys or glance around the courtroom, which was packed with victims. His parents, who observed from a back row, sobbed and embraced after he walked out looking frail on his feet and gazing straight ahead.

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.

"I plead guilty," Loughner said repeatedly in a baritone voice as Burns listed each count.

His hair closely cropped, Loughner was not the smiling, bald-headed suspect captured in a mug shot soon after the January 2011 shooting. His demeanor was a complete turnaround from a May 2011 courtroom outburst that prompted Burns to declare him incompetent.

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.

The outcome was welcomed by some victims, including Giffords herself, as a way to move on.

"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."

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.

___

Christie reported from Phoenix. Associated Press writers Pete Yost in Washington and Barry Massey in Santa Fe, N.M., contributed to this report.

Also on HuffPost:

Loading Slideshow...
  • Open Your Eyes (Snow Patrol)

    <a href="http://www.huffingtonpost.com/2011/01/12/obama-gabrielle-giffords-opens-eyes_n_808346.html" target="_hplink"><strong>(Jan. 8, 2011) --</strong></a> Four days after <a href="http://www.huffingtonpost.com/2011/01/08/gabrielle-giffords-shot-c_n_806211.html" target="_hplink">Rep. Gabrielle Giffords (D-Ariz.)</a> was wounded in a grisly shooting, President Barack Obama informed memorial service members that she opened her eyes for the first time. "I can tell you this," Obama said. "She knows we're here and she knows we love her and she knows that we will be rooting for her throughout what will be a difficult journey." (AP Photo/Chris Carlson)

  • Stand (Rascal Flatts)

    <strong><a href="http://www.huffingtonpost.com/2011/01/19/gabrielle-giffords-stands-on-two-feet_n_811355.html" target="_hplink">(Jan. 19, 2011) --</a></strong> Outside the University of Arizona's Medical Center, a decorated paper plate offered well wishes for the Tucson shooting victims. With assistance from doctors, Giffords stood on her own two feet for the first time since the incident. The congresswoman was soon transferred to TIRR Memorial Hermann Rehabilitation Hospital in Houston, one of the top-rated rehab facilities in the country. (AP Photo/Susan Montoya Bryan)

  • Stand By Me (Ben E. King)

    <strong><a href="http://www.huffingtonpost.com/2011/05/16/gabrielle-giffords-shuttle-launch_n_862400.html" target="_hplink">(May 16, 2011) --</a></strong> In this Feb. 2011 file photo, Giffords' husband Mark Kelly held a wrist band decorated with a peace sign, heart and the word 'Gabby'. By mid-May, Giffords was watching Kelly fly off into space on NASA's Endeavour expedition. The couple exchanged their wedding rings before takeoff. (Photo by Eric Kayne/Getty Images)

  • Fighter (Christina Aguilera)

    <a href="http://www.huffingtonpost.com/2011/06/28/gabrielle-giffords-public-appearance_n_885772.html" target="_hplink"><strong>(June 28, 2011) --</strong></a> Giffords made her first public appearance since being wounded in the Jan. 2011 shooting, attending a ceremony at Texas' Space Center Houston with Kelly. She received a standing ovation from the crowd. (AP Photo/southwestphotobank.com, P.K. Weis)

  • You're The Inspiration (Chicago)

    <a href="http://www.huffingtonpost.com/2011/08/01/gabrielle-giffords-debt-ceiling-vote_n_915569.html" target="_hplink"><strong>(Aug. 1, 2011) --</strong></a> Giffords completed her first House floor appearance since the shooting, attending a vote on the debt ceiling. "The reaction in the chamber was the most enthusiastic, exuberant, exhilarating -- I mean we were all crying -- thrilled -- you know, we just knew she would make a triumphant return," Rep. Debbie Wasserman Schultz (D-Fla.) said. (AP Photo/House Television)

  • Don't Stop (Fleetwood Mac)

    <a href="http://www.huffingtonpost.com/2011/08/30/gabrielle-giffords-walking-writing_n_941894.html" target="_hplink"><strong>(Aug. 30, 2011) --</strong></a> Via a Giffords spokesperson, the Associated Press learned that less than eight months after being wounded, the congresswoman was walking and writing on her own. (Photo by P.K. Weis/Giffords Campaign via Getty Images)

  • I Didn't Know My Own Strength (Whitney Houston)

    <a href="http://www.huffingtonpost.com/2011/11/10/gabrielle-giffords-tv-interview_n_1087420.html" target="_hplink"><strong>(Nov. 10, 2011) --</strong></a> Giffords' first TV interview since the shooting went to ABC News. The congresswoman answered questions with a clear voice, telling host Diane Sawyer that she felt "pretty good." Giffords added that the recovery had been "difficult."

  • It's So Hard To Say Goodbye To Yesterday (Boyz II Men)

    <a href="http://www.huffingtonpost.com/2012/01/22/gabrielle-giffords-stepping-down_n_1222168.html" target="_hplink"><strong>(Jan. 22, 2012) --</strong></a> A little more than a year after the shooting, Giffords announced that she was leaving Congress. In a Facebook video, she cited her recovery as a primary concern, thanking her constituents for their support: "I don't remember much from that horrible day, but I will never forget the trust you placed in me to be your voice," Giffords said. (AP Photo/Office of Gabrielle Giffords)

  • I Can See Clearly Now (Johnny Nash)

    <a href="http://www.huffingtonpost.com/2012/01/24/gabrielle-giffords-last-bill_n_1229309.html" target="_hplink"><strong>(Jan. 24, 2012) --</strong></a> Two days before exiting Congress, Giffords unveiled her final bill, aimed at stopping cross-border drug smugglers. "Congresswoman Giffords is committed to taking this crucial step that would help secure the border against drug smugglers," Giffords' chief of staff, Pia Carusone, said in a statement. "That's why she decided this would be the last bill she introduces before she steps down." (Photo by Jonathan Gibby/Getty Images)

  • Hero (Mariah Carey)

    <a href="http://www.huffingtonpost.com/2012/01/25/gabrielle-giffords-state-of-the-union-appearance_n_1230480.html" target="_hplink"><strong>(Jan. 24, 2012) --</strong></a> Giffords made a moving appearance at Obama's 2012 State of the Union address. Her presence drew rousing applause, inspiring colleagues on both sides of the aisle. (Photo by Saul Loeb-Pool/Getty Images)