CHARLOTTE, N.C. — The man charged with killing two North Carolina university students and wounding four others in their classroom in April pleaded guilty Thursday to two counts of first-degree murder.

Trystan Andrew Terrell also pleaded guilty Thursday to four counts of attempted murder and discharge of a firearm on educational property. State prosecutors accepted Terrell's plea during a hearing that was previously scheduled to decide whether the gunman could face the death penalty for the killings at the University of North Carolina at Charlotte.

Trystan Andrew Terrell, suspected shooter in an attack at the University of North Carolina Charlotte. Charlotte Meklenburg Police Department

Terrell had faced the charges in connection with the April 30 shooting as classmates gathered in a lecture hall.

Terrell told investigators he gave up on the attack after being tackled by one of the students who died.

Investigators said in released documents that Terrell spent months planning the shooting at the school he formerly attended. He told investigators he gave up on the attack on the spring semester class's last day after being tackled by one of the students who died, Riley Howell. Howell knocked the assailant down, buying enough time for the first officer into the classroom to capture Terrell, Charlotte-Mecklenburg Police Chief Kerr Putney said.

Witnesses said the gunman took aim at a specific table in the classroom, but it wasn't clear if he was targeting one or more of the students in particular. The faculty member who taught the class has said Terrell was enrolled in the course but quit attending in January.

"I just went into a classroom and shot the guys," Terrell told reporters hours after the shooting as police officers led him handcuffed into a law enforcement building.

Howell, 21, of Waynesville, and Ellis Reed Parlier, 19, of Midland, died after each was shot multiple times, their autopsies said. Those wounded were Sean Dehart and Drew Pescaro, both of Apex; Emily Houpt of Charlotte; and Rami Alramadhan of Saihat, Saudi Arabia.

One of the victims objected to the District Attorney's office agreeing to the guilty plea, which effectively allows Terrell to escape the death penalty.

Terrell "knew he wanted to get life in prison when planning this violent act and the DA's office is rewarding him by giving him exactly what he wanted," Pescaro wrote in a detailed statement to WCCB-TV. "It's sickening and it makes me disappointed in the DA's office, the City of Charlotte, and the State of North Carolina."