The man suspected of killing two Iowa police officers in apparent ambush attacks had been ordered by a judge to move out of his mother's home just hours earlier, court documents revealed Thursday.

A judge ruled Tuesday that 46-year-old Scott Greene had committed elder abuse against his mother, Patricia Greene, by "hitting and financially exploiting" her, according to the papers. Police suspected Greene in ambush attacks that killed two officers early Wednesday.

Meantime, a search dog found what police believed was the rifle used in the shootings, "where no person probably could have found it," Des Moines police spokesman Sgt. Paul Parizek said.

CAUGHT ON VIDEO: OFFICER WRESTLES MAN WHO SPEEDS OFF IN POLICE CRUISER

The judge ordered Greene to move out of his mother's home in Urbandale, a suburb of Des Moines, before Nov. 6 and to stay away for a year. Greene was told he could go to the home to remove his belongings if accompanied by an officer.

Patricia Greene applied for a restraining order against her son on Oct. 19, days after she was charged with hitting him. The 66-year-old wrote that her son told one of her friends that he would move and not bother her again if she gave him $20,000.

Scott Greene briefly worked for a construction company last month before the firm reported he quit. He'd been "pretty desperate" to find work and told Central Iowa Fencing in Ankeny he had a teenage daughter to support, the company's office manager, Sara Nicklin, told The Associated Press.

She added that Greene was hired even though he had no experience building fences. He was sent home on his third day "because he was not taking directions and wasn't working," and when told he could work on a different crew, "he chose not to show up," according to Nicklin.

CALIFORNIA SHERIFF'S DEPUTY ACCIDENTALLY SHOT, KILLED BY COLLEAGUE

Greene apparently posted a cellphone video online last week indicating he was fired after reporting unsafe driving. Nicklin denied Greene was fired and said she hadn't seen the video.

Greene was formally charged Thursday afternoon with two counts of first-degree murder in the ambush shooting deaths.

The Des Moines Police Department said that Greene was put under arrest Thursday afternoon after being questioned by detectives.

The department said that Greene was put into the handcuffs that had belonged to the officers who were killed. Greene is expected to be transported to the county jail. He faces life in prison if convicted.

Greene was suspected of killing 24-year-old Justin Martin, who had been with the force in the Des Moines suburb of Urbandale since 2015, and 38-year-old Sgt. Anthony Beminio, who joined the Des Moines department in 2005.

Police responded to a report of shots fired shortly after 1 a.m. and found the Urbandale officer. Authorities from several agencies soon saturated the area. About 20 minutes later, they discovered the Des Moines officer, who had responded to the first shooting, Parizek said.

The shootings unfolded less than 2 miles apart, and both took place along main streets that cut through residential areas.

In the first shooting, investigators believed the gunman walked up to the officer's car and fired more than two dozen rounds.

"I wouldn't call it a confrontation," Urbandale Police Chief Ross McCarty said. "I don't think he may have even been aware that there was a gunman next to him."

The shootings followed a string of police killings in recent months, including ambushes of officers in Dallas and Baton Rouge, Louisiana. Five officers were killed July 7 in Dallas. Three more were killed later that month in Baton Rouge.

In a confrontation at an Urbandale High School football game, which Greene videotaped and posted on social media, he appeared to be trying to antagonize black fans when he shook a Confederate flag in front of them during the national anthem, McCarty said.

In the video, officers could be seen asking Greene to leave school property while he insisted he was assaulted and his flag was stolen. He demanded officers file theft and assault charges, saying someone hit his head and grabbed the flag.

In a back-and-forth with officers lasting nearly 11 minutes, officers said they could take a report but they could not let Greene back inside the stadium because the school banned him from the property. They also noted they were returning his flag and asked if he purposely wanted to create a conflict by displaying it near African-Americans.

"I was peacefully protesting," he responded. "That's my constitutional right."

The video ended with Greene promising not to "set foot on" school property and officers saying they would take down his information.

Ardis Gardner of Des Moines told The Associated Press he was at the Oct. 14 football game to watch his teenage son play.

Gardner, 47, who is black, sat with a group of other friends and family members when Greene, who was dressed in Army fatigues, approached them within a few feet and waved the flag at them during the national anthem.

"I was angry," said Gardner, who typically sits during the national anthem and prays. "It was senior night, and the spotlight should have been on those senior players. This was calculated for him to do it at that moment."

A week later, Gardner said, Greene followed him and a group of black parents into another football game with a dog that was wearing a gun holster and a Confederate flag vest. Greene sat nearby again.

After the video was posted on YouTube, someone identifying himself as Scott Greene commented, "I was offended by the blacks sitting through our anthem. Thousands more whites fought and died for their freedom. However this is not about the Armed forces, they are cop haters."

In other incidents, court records show Greene was jailed and charged with interfering with official acts after resisting Urbandale police officers who tried to pat him down for a weapon on April 10, 2014. An Urbandale officer described him as hostile and combative. Greene entered a guilty plea and was fined.

Two days later, Urbandale police were called to answer a complaint of harassment at the apartment complex where Greene lived. The complaint said he threatened to kill another man during a confrontation in the parking lot and yelled a racial slur used against blacks. Greene was charged with harassment.

He pleaded guilty and received a suspended jail sentence and a year of probation. An officer wrote that Greene had complied with the terms of his probation, noting that he had obtained a mental health evaluation and "reports to have complied with the medication recommendations." The officer did not elaborate.

It was unclear if either of the shootings was captured on police cameras.

The Associated Press contributed to this report.