A California man has been charged with shooting a Cicero police officer during a chaotic rush-hour encounter that also prompted a concealed-carry permit holder to open fire Thursday afternoon on a busy Stevenson Expressway ramp.

Daniel Mageo, of Long Beach, California, faces two counts of attempted first-degree murder and one count of aggravated battery with a firearm, Chicago police announced on Saturday.

Mageo, 27, is a convicted felon and a registered sex offender who had an active California parole violation warrant out for his arrest, according to Cicero town officials.

Authorities say Mageo shot Cicero Police Officer Luis Duarte four times during the encounter near the 4200 block of South Cicero Avenue, but it might have been worse if the armed citizen hadn’t stepped in.

The incident began after Duarte, 31, and his partner tried to pull over Mageo’s vehicle about 5 p.m. in the 3900 block of South Cicero, but he took off until he got caught in traffic on the ramp to southbound Interstate 55, Cicero police said hours after the shooting.

Mageo then got out and opened fire, hitting Duarte twice in the arm, once in the leg and once in the abdomen, officials said.

Duarte’s partner returned fire, as did a concealed-carry holder who had been sitting in traffic on Cicero Avenue, police said.

Mageo was shot once and taken to Stroger Hospital in serious condition, officials said. It wasn’t clear if he was shot by police or the armed bystander.

“We were lucky enough to have a citizen on the street there who’s a concealed-carry holder, and he also engaged in gunfire,” Cicero Police Supt. Jerry Chlada Jr. said outside Mount Sinai Hospital, where Duarte underwent Thursday night.

On Friday, police said the four-year veteran officer was recovering in good condition.

Mageo, who was arrested by Chicago police because the shooting happened in city limits, was scheduled to be in bond court Saturday afternoon.

Illinois State Police are investigating the officers’ use of force.