(CNN) A gunman killed five people before taking his own life Wednesday in what appeared to be targeted attacks related to a domestic violence case, authorities said Thursday.

The shooting spree unfolded in less than 40 minutes across three locations in proximity to each other near Bakersfield, California, Kern County Sheriff Donny Youngblood said.

The gunman, identified as Javier Casarez, 54, killed himself as a sheriff's deputy confronted him, Youngblood said.

Along the way, the gunman stole a vehicle from a woman and her child but let them live, Youngblood said. He told the woman something to the effect of "he wasn't a bad person," Youngblood said.

Javier Casarez

Police are investigating the relationship between the gunman and the victims. But it appears Casarez and victim Petra Maribel Bolanos De Casarez, 45, had begun to divorce about four months ago, the sheriff said. They were in "divorce proceedings" and she had recently sought a hearing related to child support and property, he said.

Read More