The man charged with firing a gun through the window of a school bus and wounding the 78-year-old driver on a busy Minneapolis interstate this week shot and killed an armed teenage robber in a St. Paul park three years ago, authorities said.

Ramsey County prosecutors at the time declined to press charges, saying that Kenneth Lilly, 31, was “legally justified” when he shot 16-year-old Lavauntai Broadbent. Broadbent was killed on July 31, 2015, after he brandished a handgun at Lilly and another person at Shadow Falls Park in an apparent robbery. Lilly drew his own gun — for which he had a permit to carry — and fired at Broadbent, who was wearing a mask and gloves, police said. Prosecutors declined to charge Lilly the following month.

Although Broadbent’s death was widely reported, Lilly was never named by authorities. Spokesmen for the Ramsey County Attorney’s Office and St. Paul police confirmed that he was involved in the incident.

Now Lilly, of St. Paul, faces charges of second-degree attempted murder and second-degree assault with a ­dangerous weapon in the school bus shooting Tuesday on Interstate 35W near downtown Minneapolis. An 8-year-old bus passenger was not hurt.

Lilly, who was arrested immediately afterward, told investigators he fired at the stopped bus after a fender-bender during a snowstorm traffic jam out of fear for his safety, the charges said.

Lilly was jailed in lieu of $500,000 bail, but posted bond and was released the night before he made his first appearance in Hennepin County District Court. Lilly answered questions from Judge Peter Cahill, who ordered that he surrender his permit to carry, stay away from the alleged victim and refrain from possessing guns or ammunition. His next court date is set for March 8.

After the hearing, Lilly stood silently alongside his attorney, Thomas Plunkett, who called the shooting “a complicated case.”

“More information will be coming out about the case,” he said. “We appreciate that you give us and Mr. Lilly the opportunity to complete our investigation so that we can do a fair job for everyone.”

Afterward, Lilly and his attorneys crossed the street to confer with supporters who were at the hearing, and who declined to speak with reporters.

In response to the 2015 case, Plunkett said that the robbery suspect was a member of a local street gang, which had been in the midst of a “multiday crime spree.” Juvenile court petitions against Broadbent and his three alleged accomplices suggest they were involved in a similar robbery and other crimes before the incident at Shadow Falls Park.

“Mr. Lilly was the victim of a horrible violent crime where he had to act to save his life and the life of a young lady,” Plunkett said in a statement. “He takes no joy in these events, and has struggled with the inevitable emotional turmoil that follows being forced to act in such a way.”

According to a police report, Lilly said he was checking on his parents’ home while they were out of town and decided to drive to Shadow Falls Park at Summit Avenue and Mississippi River Boulevard late that night to view the blue moon. He met a woman sitting on the bluff and they began chatting. About 15 minutes later, they were approached by a man who asked to use Lilly’s phone, Lilly told police. He was reaching for it when Broadbent intervened, pointed a handgun at Lilly and the woman and demanded that he empty his pockets. Lilly “feared for his life and immediately lifted up his shirt which concealed a Glock 23 loaded with hollow point bullets on his right hip,” then fired four to five rounds at Broadbent. Broadbent was declared dead at the scene.

Police seized the gun from Lilly at the scene. Upon searching him, they also found three Glock 40 magazines in his left front pocket, along with pepper spray, two pocket knives, a wallet, flashlight, cellphone and a set of car keys.

Prosecutors announced on Aug. 19, 2015, that Lilly would not be charged, saying the shooting was justified under state statutes. Dennis Gerhardstein, a spokesman for the Ramsey County Attorney’s Office, said in an e-mail that prosecutors wouldn’t reopen the earlier case “unless law enforcement presents new information regarding the July 31, 2015 incident.”

A message left at a phone number listed for Broadbent’s mother went unreturned.

According to charges filed Thursday against Lilly in connection with the Minneapolis incident, the bus driver was shot while behind the wheel about 2:15 p.m. after he tried to merge onto the interstate and collided with Lilly’s car. The driver said he was unaware of the collision, but state troopers did see paint from the bus on Lilly’s vehicle.

Footage from a MnDOT traffic camera shows Lilly stopping on the interstate and walking toward the bus, which was stopped behind him. He is seen apparently shouting at the driver. As Lilly walks toward the driver’s side of the bus, the driver appears to try to steer the bus back into traffic. Lilly begins walking to the front of the bus before shooting, according to a criminal complaint. The gunfire grazed the driver in the head and hit his left arm, according to the charges. Authorities would not reveal how close the shots came to hitting the girl.

MnDOT video showed Lilly getting on his phone after the shooting, reportedly to call 911. A state trooper arrived, but did not immediately take Lilly into custody. It wasn’t until a second trooper arrived, gun drawn, that he was handcuffed.

The driver was “alert and conscious” when taken from the scene ahead of surgery at HCMC for his injuries.

“The safety of the kids on my bus are my first priority, and I care for them as if they were my own grandkids,” he said in a statement Thursday.

While the criminal complaint points out that Lilly was in a security guard’s uniform, it is unclear where he is employed. He does not appear to have a criminal record in Minnesota beyond minor traffic violations.