CHARLOTTE, N.C. — The UNCC gunman pleaded guilty in a Charlotte courtroom Thursday for the April 30 school shooting that killed two students and injured four other students.

The plea is part of a proposed deal that would spare his life, a family member told WCNC NBC Charlotte Wednesday. The judge Thursday sentenced the shooter to two terms of life in prison.

Without a deal, the gunman, Trystan Andrew Terrell, could have faced the death penalty. 

In court Thursday, prosecutors said the suspect was burdened with student debt. He explained to them that he committed the shooting as a way to go to prison.

RELATED: UNC Charlotte shooting survivor vents frustration over gunman sentencing

In a tweet Wednesday night before the court hearing, Drew Pescaro, one of the four students wounded, said:

"So instead of finding a way to pay off his debt he decides it would be a great idea to get jail for life instead. He decides the way to get jail for life is to purchase a pistol, and show up to a college campus on the last day of classes and shoot up a classroom, killing two and injuring four more."

The shooter's attorney said the shooter "is so sorry" for the shooting and suffers from "a strain of autism."

In court Thursday, prosecutors said the shooter fired 17 rounds. The state said he was firing randomly at students he did not personally know.

In May, the suspect was indicted on two counts of first-degree murder. He was also charged with four counts of attempted murder, four counts of assault with a deadly weapon with intent to kill, possession of a firearm on educational property and discharging a firearm on education property.

As a part of his plea deal, prosecutors dropped the four assault charges related to the wounded students.

A spokesperson for the Mecklenburg County, North Carolina District Attorney's Office declined to comment before Thursday's court session but Mecklenburg County District Attorney Spencer B. Merriweather III defended the plea deal.

"There is nothing certainly certain about trial. There is great uncertainty, even more uncertainty when it comes to a trial involving the death penalty," Merriweather said.

"It ensures that the man who committed these horrible crimes will never harm anyone again," he added.

The plea deal severely restricted the suspect's ability to appeal, according to the D.A.'s office.

Ellis Parlier, 19, and Riley Howell, 21, were both shot and killed when the gunman walked into their UNCC exam room and opened fire.

UNCC UNC Charlotte shoting victims
Riley Howell (left) and Ellis "Reed" Parlier (right) were killed during the school shooting on the campus of UNCC in Charlotte on April 30.
WCNC

Parlier's mother was among those who addressed the court during Thursday's proceeding.

"His life was ended by a selfish, cowardly, waste of a human being. May he rot in hell and experience torture ever day until you're dead," said Julie Parlier.

Riley Howell's Mother also gave a statement.

"Riley and Reed's light, goodness and depth of love is what reigns supreme in our hearts," said Natalie Henry-Howell.

19-year-old Pescaro, 20-year-old Rami Alramadhan, 23-year-old Emily Houpt and 20-year-old Sean DeHart were hurt in the school shooting.

On the eve of the shooter's sentencing, Pescaro told WCNC NBC Charlotte that he would not be in court Thursday.

Drew Pescaro statement
In a statement released to WCNC NBC Charlotte Wednesday, UNCC shooting victim Drew Pescaro said he would not be attending the court proceeding.
WCNC

In a statement, Pescaro said in part:

"After a meeting at the DA’s office yesterday morning, I feel that there is no purpose in me showing up as I feel that the DA’s office did not properly represent us victims. I feel like our thoughts and emotions on the case were not taken into consideration and that they chose to take the path of least resistance for the State for the City of Charlotte. I am not allowed to directly say what I mean by that but you will see what I mean when the court case takes place tomorrow.

You can read Pescaro's full statement.

The suspect was a history major at UNC Charlotte. Sources told NBC Charlotte he dropped out of the class earlier in the semester.

In a statement released after Thursday's sentencing, UNCC Chancellor Philip DeBois said in part:

"Today's news... allows our community to continue healing and brings a definite end to the criminal proceedings. We will never forget this tragic event, and remain focused on honoring the victims and their families."

Warrants previously obtained by WCNC NBC Charlotte said the shooter had been planning the attack for months.

The documents explained the suspect researched other mass shootings and took video of the classroom with his cell phone.

When officers arrived after the shooting, the suspect was lying on the floor between two victims. When asked if he'd been shot, he responded he'd been tackled, according to warrants.

RELATED: UNCC: Area in Kennedy Hall where deadly shooting occurred won't be used in upcoming school year

The shooter admitted to officers that he was the shooter, according to documents. Officers recovered a Samsung cell phone, a handgun, and a bag containing several more loaded magazines when they arrested the suspect, according to warrants.

During a search of the suspect's apartment, detectives seized several items, including a laptop, three gun magazines, six boxes of ammo and paper targets.

RELATED: UNCC Survivor on gun laws: 'Was the shooting at Charlotte not inspiring enough?'