ST. LOUIS — A white former St. Louis police officer charged with killing a black man "executed" him after a car chase, then planted a gun in the slain drug suspect's vehicle as an excuse for opening fire, a prosecutor told jurors Tuesday.

But an attorney for the officer denied the prosecutor's allegations during opening statements in the first-degree murder trial for Jason Stockley, saying the officer was protecting himself against an armed and dangerous felon.

Former St. Louis city police officer Jason Stockley, 36, center, arrives with his legal team on Tuesday, Aug. 1, 2017, at the Carnahan Courthouse in St. Louis. Laurie Skrivan / AP

It was the first time that prosecutors have revealed publicly that they believe that Stockley, 36, planted a gun on 24-year-old Anthony Lamar Smith after Smith was shot in December 2011. Stockley, who left the department in 2013, wasn't charged until last year, after then-Circuit Attorney Jennifer Joyce cited unspecified new evidence. The first-degree murder trial will be decided by a judge rather than a jury despite objections from prosecutors.

It's unusual for officers to be charged with killing suspects while on duty, and few officers are convicted in such deaths.

A key issue in the trial is the unloaded .38-caliber revolver that another officer later found inside Smith's rented Buick. Three cartridges were next to the gun. Stockley has said he unloaded the weapon as a safety precaution after shooting Smith.

Assistant Circuit Attorney Aaron Levinson said that after Stockley shot Smith, he went into Smith's rented Buick multiple times.

Stockley's DNA — but not Smith's — was found on the gun, though Smith's DNA was found on a bag of heroin inside the car, the prosecutor said.

Related: Why It's So Hard to Convict Police Officers

"Anthony Smith did not deserve to die," Levinson said. "He may have fled from police, but he did not deserve to be executed."

But Stockley's attorney, Neil Bruntrager, said both officers saw the gun inside the car before the chase started. Stockley opened fire only after Smith refused commands to put up his hands and reached along the seat "in the area where the gun was," Bruntrager said, describing Smith as a parole violator "who decided to do whatever was necessary to avoid arrest because he was going to jail."

Video from a police dashboard camera and witnesses, along with DNA evidence, are expected to play a big role in the trial of Stockley, described by Bruntrager as a West Point graduate who served in Iraq and graduated first in his police academy class.

Annie Smith, the mother of Anthony Lamar Smith, enters the Carnahan courthouse with activist Anthony Shahid for opening statements in the trial of former St. Louis police officer Jason Stockley on Tuesday, Aug. 1, 2017, in St. Louis. Robert Cohen / AP

The shooting happened after Stockley and his partner spotted Smith in a suspected drug transaction in the parking lot of a fast-food restaurant.

Police dashboard recordings and two videos show the officers pulled behind Smith's car. As they got out, Smith backed into the police SUV and sped past Stockley, who was carrying his personal AK-47 rifle that was nearly knocked from his hands. Police have said Stockley was not authorized to carry that weapon on duty.

Stockley fired several shots from his department-issued pistol, breaking the rear window of the Buick, and the chase ensued, with speeds reaching 87 mph. Stockley reported shots being fired. According to court records, he then said, "Going to kill this (expletive), don't you know it," — something Bruntrager denied.

The officers eventually rammed their SUV into the back of Smith's car, causing its air bags to deploy. The officers got out, leading to the fatal encounter.

The courtroom was filled with onlookers, including many people active in protests in nearby Ferguson, Missouri, following the fatal police shooting of Michael Brown in 2014. Supporters of Stockley were also present. Circuit Judge Timothy Wilson opened the hearing with a warning that any outbursts would not be tolerated.

"Earlier this year, Ringling Brothers Circus died," the judge said. "It will not be resurrected here."