A man who police said shot and killed five people -- including his ex-wife -- before turning his gun on himself believed his wife had cheated on him, according to court documents.

Javier Casarez, 54, filed for divorce in December from his wife of 28 years, Petra Maribel Bolanos de Casarez, court records show. The divorce was finalized in June.

"We are getting divorced because my wife cheated on me," Casarez wrote in his divorce petition, which was obtained by CBS47 in Fresno. "I would like for the judge to grant me a subpoena for me to see the texts (sic) messages to whom my wife texted to."

He then gave the court the phone numbers to which he said his wife sent text messages.

CBS47 reported that two of the phone numbers were tied to two of the male victims in the mass shooting.

>> Related story: Gunman kills 5, self in Bakersfield rampage, police say

This still image from a Kern County deputy's body camera shows a standoff between deputies and Javier Casarez, 54, moments before Casarez fatally shot himself Wednesday, Sept. 12, 2018, in Bakersfield, California. Kern County Sheriff Donny Youngblood said Casarez killed five other people, including his ex-wife, before turning the gun on himself.

Credit: Kern County Sheriff's Office via AP

icon to expand image

Credit: Kern County Sheriff's Office via AP

Kern County Sheriff Donny Youngblood said during a Thursday news conference that Casarez got his 45-year-old ex-wife to accompany him to his workplace, T&T Trucking, around 5:20 p.m. Wednesday. There, he confronted Manuel Contreras, who KGET in Bakersfield identified as a supervisor at the trucking company.

Casarez pulled out a .50-caliber handgun and killed Contreras, 50, before fatally shooting his ex-wife, Youngblood said.

A second worker at the trucking company, 50-year-old Antonio Valdez, tried to run away, the sheriff said. Casarez got in his car and chased him down, shooting him outside the nearby Bear Mountain Sports.

After killing Valdez, Casarez drove to a home a short distance away on Breckenridge Road, where he confronted Eliseo Cazares, 57, Youngblood said. Cazares’ daughter, Laura Garcia, 31, was also at the home.

"We believe that she may have tried to intervene to keep the suspect from approaching her father," Youngblood said Thursday. "He shot and killed both of them."

KGET reported that Casarez took out a personal loan from Cazares in 2010. It was not immediately clear if that debt played a part in Wednesday's shooting.

The news station also reported that children in the home, believed to belong to Garcia, were not harmed in the shooting.

Casarez fled that crime scene by carjacking a woman, whom he told, “I’m not a bad guy.” He let the woman remove her child and herself from the car before driving it from the scene.

Watch the body camera footage of deputies’ brief standoff with Casarez, which ended with the gunman’s suicide. WARNING: Even though Casarez is blurred at the time of his self-inflicted gunshot, some viewers may find the video too graphic to watch.

The gunman then went to a friend's auto repair business on Edison Highway, where he was confronted by sheriff's deputies, Youngblood said. Following some back and forth conversation, Casarez fatally shot himself in the stomach.

His suicide was captured on a deputy’s body camera.

Casarez and his wife leave behind three children, ages 18, 17, and 10, according to the divorce records.

BakersfieldNow.com reported that Bolanos de Casarez told the court she lived in fear of her ex-husband, who she said filed for divorce and then hid the documents from her in the home they shared.

When the April divorce hearing date passed, Casarez kicked Bolanos De Casarez out of their home and moved into an apartment with the couple's youngest daughter, the news site reported.

He then cut his wife and their two older children off, financially.

Court documents obtained by the news site said Bolanos De Casarez said she was “always walking on eggshells” while they were married.

"If anything was out of place he would get very upset," she said in the documents

Unable to read English, she could not read the divorce papers and other records in the divorce proceedings.

"It also took me some time to get over my fear and get the courage to ask for help," Bolanos De Casarez said, according to the documents.

Watch the Kern County Sheriff’s Office news conference on Wednesday’s shootings below.

Neighbors of the divorced couple expressed shock over the slayings. One neighbor, Carol Gandola, told BakersfieldNow.com that she saw him the week before the mass shooting.

"I'd seen him last week when I went over to his yard and he seemed happy," Gandola said. "He came over to give his regards because I had lost my husband and he hadn't been able to get over to see me, and all of the sudden, he broke down crying, because of his wife leaving."

Gandola said she was having a hard time wrapping her mind around the events that took place.

“I just had a really hard time putting my mind around that he would shoot five people and commit suicide,” she said. “It’s just mind boggling.”