RIVERSIDE, Calif. — A driver stopped by police pulled out a rifle and opened fire, killing a California Highway Patrol officer and wounding two others during a shootout on a freeway overpass that left the gunman dead and sent terrified motorists running for cover.

Officer Andrew Moye, Jr., 34, died in the gunfight as dozens of bullets flew Monday afternoon in Riverside, east of Los Angeles. Two civilians received minor injuries.

The other officers were both shot in their legs, CHP Chief Bill Dance said Tuesday. One was in critical condition and the other was serious, but both are expected to survive, he said.

The gunman was identified by the Riverside County coroner’s office as Aaron Luther, 49, and authorities say he had a criminal record that included an attempted murder conviction in 1994.

Moye had pulled over a pickup and was doing paperwork to impound it when Luther, who was outside the vehicle, reached in, grabbed a rifle and fatally wounded the officer, authorities said. Moye was able to radio for help and other officers engaged in a “long and horrific gunbattle,” Riverside Police Chief Sergio Diaz said.

Authorities said it was unclear what prompted Moye to stop the truck or for Luther to open fire.

Moye’s flag-draped body was removed from a hospital and placed in a hearse Monday night. Motorcycle officers then led a procession as the hearse was driven to the county coroner’s office.

“I am devastated by the tragedy,” CHP Commissioner Warren Stanley said in a tweet.

Gov. Gavin Newsom ordered flags at half-staff at the state Capitol.

Relatives said Moye had been with the CHP for about four years.

Dance said Moye was an “outstanding” officer devoted to public service.

“His mother told me this was his dream job and he loved going to work,” he said. “It’s what he always wanted to do.”

He is survived by his wife, mother, father, stepfather, two brothers, two sisters and a large extended family, Dance said.

The gunfight occurred during the afternoon commute when traffic was heavy.

Jennifer Moctezuma, 31, of Moreno Valley, told the Los Angeles Times she was driving home with her 6-year-old twins when a bullet flew through her front windshield.

Charles Childress, 56, a retired Marine also from Moreno Valley, was in the car behind her and led the family as they crawled to the bottom of a bridge to hide.

“He’s my hero,” Moctezuma said of Childress.

Luther’s father, Dennis Luther, said he watched the events unfold on television. “It’s hard. I love him. And I’m sorry for the policeman,” he told KABC-TV. “I’m devastated. I just can’t believe it.”

After his pickup was impounded, Aaron Luther called his wife to pick him up, his father said. When she arrived, the tow truck was there.

“She said she heard ‘pop, pop, pop’ gunfire, and then a bullet went through the windshield of her car,” Dennis Luther said.

He said his son recently seemed depressed, was having knee pain and marital problems but was devoted to his children.

Jeffrey Callison, a spokesman for the Department of Corrections and Rehabilitation, said Aaron Luther was sentenced to 12 years in prison for attempted second-degree murder and an enhancement for the use of a firearm, as well as burglary charges. He began his sentence in 1994 and was paroled in April 2004.

Court records show Luther was arrested in 2007 on felony assault charges and took a no-contest plea deal that sentenced him to 90 days in jail.

He also was arrested in 2017 on suspicion of driving while his license was suspended or revoked, records show.

As a felon, Luther was not supposed to have a gun and his father said he’s not sure how his son came to possess one.