BRIGHTON, Colo. (CBS4)– The man charged with the shooting deaths of three people inside a crowded Walmart in Thornton last fall has pleaded guilty in the case.

Scott Ostrem, 48, was found mentally competent to stand trial earlier this summer. Last month, the judge entered a plea of not guilty on his behalf and set the case for trial.

READ MORE: Ryan Yarwood Arrested After Eluding Police In Stolen Vehicle

That all changed on Wednesday when Ostrem agreed to plead guilty to three counts of first-degree murder to avoid the possibility of the death penalty.

Scott Ostrem (credit: CBS)

He is accused of killing Pamela Marques, 52, of Denver, Carlos Moreno, 66, of Thornton, and Victor Vasquez, 26, of Denver.

READ MORE: Concessionaires Looking To Fill Thousands Of Open Positions At Denver International Airport

(credit: CBS)

Ostrem was charged with with 37 counts, including three counts of first-degree murder, three counts of first-degree murder extreme indifference and 30 counts attempted first-degree murder.

Victor Vasquez, Pamela Marques and Carlos Moreno

MORE NEWS: What Is Sweetwater Lake, A 'Hidden Gem' That's Soon-To-Be Colorado's 43rd State Park?

He will be sentenced to life in prison without parole on Oct. 19 in Adams County Court.