Scott Ostrem, 47, center, leaves a hearing in Adams County, Colo., court Friday, Nov. 3, 2017, in Brighton, Colo. 

(AP Photo)

A Colorado man pleaded guilty to three counts of first-degree murder Wednesday as part of a plea agreement that calls for him to serve life in prison without the possibility of parole after opening fire inside a crowded Walmart in suburban Denver.

Scott Ostrem, 48, also pleaded guilty to one count of attempted first-degree murder for endangering 45 other people inside the store in Thornton on Nov. 1, 2017.

Adams County District Attorney Dave Young said Ostrem, through his attorneys, approached prosecutors in August offering to plead guilty in exchange for a life sentence.

At the time, Young said he was still considering whether to seek the death penalty against Ostrem. During discussions about the death penalty, Young said victims' relatives "were unanimous" in wanting a quicker resolution to the court proceedings.

"The reason why we did this plea is to bring a sense of closure, at least in the court system, to them," Young said. "I can't sit here and tell you that they're happy because they're not. I don't know that they will ever be happy with any resolution in this case."

Police have said Ostrem walked into the store on a weekday evening, fired seven shots in about 20 seconds and left without saying a word.

Ostrem was working as a metal fabricator at a roofing company and his boss has previously said that Ostrem abruptly left work hours before the shooting.

Police said they later learned that he went to a shooting range. Surveillance video showed Ostrem firing at a target for a few minutes, then leaving.

At a June court hearing, police said they had not found the murder weapon, but that shell casings found at the store matched those found at the shooting range.

Police used surveillance video from about 200 cameras inside and outside the store to identify Ostrem and his car in the hours after the shooting. He was arrested the following day after a brief car chase.

Authorities have been unable to determine a motive for the shooting.

"The families would like to know and I'm sure everybody in the public would like to know why this happened," Young said. "But there's only one person that knows that."

Ostrem will be given a chance to make a statement during the sentencing hearing but Young did not know whether Ostrem plans to speak.

Court staff reserved half of the courtroom for family members of the three victims: Pamela Marques, 52, and Victor Vasquez, 26, both of Denver, and Carlos Moreno, 66, of Thornton.

Some people began crying as the judge read the charges aloud, including the names of each victim of first-degree murder. One woman wore a black T-shirt displaying a photo of Vasquez, along with the years of his birth and death.

Prosecutors said some family members plan to speak during the formal sentencing hearing set for Oct. 19. They declined to speak with reporters after Wednesday's hearing.

Ostrem told Judge Mark Warner that he understood pleading guilty meant surrendering many rights, including a trial.

He responded "yes" when Warner asked if Ostrem was thinking clearly and was satisfied with his attorneys' work. He replied "no" when Warner asked if Ostrem was suffering from any mental illness.

His attorneys declined to comment after the hearing.

Ostrem's stepsister, Michelle Willoughby, told The Denver Post shortly after his arrest that he has been tormented by voices in his head since taking LSD nearly 30 years ago. She said Ostrem had been outgoing, sociable and athletic before taking the drug at a party, and afterward he became a recluse haunted by voices saying the devil was after him.

An Adams County judge ruled earlier this year that Ostrem was competent to stand trial based on an evaluation at the state mental health hospital.

Ostrem had been set for trial in January on six counts of first-degree murder and 30 counts of attempted first-degree murder.