An Army sergeant pleaded guilty Monday to killing four soldiers and a Navy officer in 2009 at mental health clinic in Baghdad during the Iraq War.

The plea at a military court at Joint Base Lewis-McChord means Sgt. John Russell will avoid the death sentence. His maximum sentence would be a life term.

Russell — who is from Sherman, Texas — went on a shooting spree at the Camp Liberty Combat Stress Center near Baghdad in May 2009. It was one of the worst instances of soldier-on-soldier violence in the Iraq War.

Russell was nearing the end of his third tour when his behavior changed, members of his unit testified in 2009. They said he became more distant in the days before the May 11, 2009, attack and that he seemed paranoid that his unit was trying to end his career.

On May 8, Russell sought help at a combat stress clinic at Camp Stryker, where his unit was located. On May 10, Russell was referred to the Camp Liberty clinic, where he received counseling and prescription medication.

The following day witnesses saw Russell crying and talking about hurting himself. He went back to the Camp Liberty clinic, where a doctor told him he needed to get help or he would hurt himself. Russell tried to surrender to military police to lock him up so he wouldn’t hurt himself or others, witnesses said.

Military prosecutors said Russell left the clinic and later returned with a rifle he took from his unit headquarters and began firing.

Killed in the shooting were Navy Cmdr. Charles Springle, 52, of Wilmington, N.C., and four Army service members: Pfc. Michael Edward Yates Jr., 19, of Federalsburg, Md.; Dr. Matthew Houseal, of Amarillo, Texas; Sgt. Christian E. Bueno-Galdos, 25, of Paterson, N.J.; and Spc. Jacob D. Barton, 20, of Lenox, Mo.

Two evaluations presented during a 2009 hearing said Russell suffered from severe depression with psychotic features and chronic post-traumatic stress disorder. A March 2011 evaluation said the major depression with psychotic features was in partial remission.

His defense team has said he has no memory of the killings, and witnesses have said he appeared distant and paranoid before the attack.

Family members of Russell’s victims were in court to observe the hearing.

Russell’s pretrial agreement includes a contested portion that remains to be argued in court. He refused to plead guilty to murdering the service members with premeditation. Prosecutors planned to argue that point later on Monday.