Before he was taken into custody Wednesday as the lone suspect in the ambush killings of two police officers, Scott Michael Greene had clashed with increasing frequency and anger with police, strangers and his own family.

In the weeks leading up to the shooting, police asked Greene, 46, to leave a high school football game in the Des Moines suburb after he waved a Confederate flag at African Americans in the stands and became combative.

Two days later, Greene got into a fight with his mother and accused her of domestic abuse, forcing her to pack up and leave her own house, according to court records and neighbors. His mother accused him of elder abuse, filed last week for a protective order against Greene and described him as mentally disturbed and volatile.

Early Wednesday morning, Greene walked up to the first officer, rookie Justin Martin, 24, and pumped 15 to 30 rounds into his squad car, said Urbandale Police Chief Ross McCarty. About 20 minutes later, as police swarmed the area, they found Des Moines Sgt. Anthony Beminio, 38, dead in his patrol car.

Police did not describe any possible connection between Greene and the officers or motivation for the shooting, which followed ambushes on police in Dallas and Baton Rouge in July that killed eight.

The owner of a guitar shop across the street from Greene’s house said Greene and Martin may have crossed paths last week during a burglary.

Paul Wilson, owner of Ye Olde Guitar Shoppe, said Greene saw the burglary as it was happening and called police, thwarting the break-in. The officer who arrived to investigate was Martin, one of the officers Greene is accused of killing.

Later that day, Wilson said, Greene returned to the store and talked with Wilson for an hour. Greene told the owner he had post-traumatic stress disorder and used a pit bull as a service dog but did not say what had led to his PTSD.

At one point in the conversation, Wilson said, Greene pulled out a retractable baton and started hitting the table. Greene said that if he was ever bothered, he would “break their collarbone” and that if that did not work, “they’d meet Mr. 9 millimeter.”

“He looked like a guy ready to blow,” said Wilson, who showed a reporter the mangled safe that burglars had tried to open. “He was seething underneath. He was someone you wouldn’t want to cross but didn’t think he was dangerous. Could tell he had a short fuse if you messed with him too much.”

Two police officers in Iowa were shot and killed Wednesday in a pair of “ambush-style attacks,” the Des Moines Police Department said. Here’s what you should know. (Monica Akhtar/The Washington Post)

The first shooting took place at 1:06 a.m. at an intersection next to Urbandale High School, where Greene had been removed from a football game two weeks before.

Russell Cheatem, an Urbandale resident, told the Des Moines Register that he heard gunfire and then saw a man who was standing next to Martin’s police car get into his truck and drive away. After several minutes, Cheatem said he grew concerned that the police car had not moved, so he walked over. “I pulled the door open and realized there was nothing I could do for him,” Cheatem said.

After an hours-long manhunt, just before 9 a.m., authorities apprehended Greene. He had been walking down a rural road and flagged down a person on a tractor, asking them to call 911, according to authorities.

When the Dallas County sheriff’s office and Iowa State Patrol responded, the man identified himself as Greene and said he had “an existing medical condition that was flaring up,” said Sgt. Paul Parizek, a Des Moines police spokesman.

Greene was brought to a hospital. He is not under arrest because he has not yet been charged, Parizek said. Police say they do not believe anyone else was involved.

The shootings come at a time when relationships between police and some in their communities are increasingly wary. And they have renewed fears among law enforcement. In Des Moines, police were ordered Wednesday to patrol in pairs for safety.

Parizek said Wednesday with a gunman on the loose that “there is clearly a danger if you’re a police officer.” He added, “These guys were gunned down, sitting in their car doing nothing wrong.”

He also alluded to broader tensions between police and those they are sworn to protect.

“We’re very well aware of the society that we’re living in right now and the time, and that there are some not-so-positive views of law enforcement that a segment of our population holds,” Parizek said. But he said police would be vigilant about their safety while still doing their jobs, saying, “If we don’t provide the service in the area that we do, with the personal-type service that we do, we’re nothing more than an occupying army.”

Police said Wednesday that Greene had been “known to law enforcement.” Court records show that a man with Greene’s name and birth date had a history of run-ins with police, including charges of assault and harassment, some of which were dismissed.

On at least two occasions — including one just weeks before the shootings — Greene apparently was involved in tense, racially infused confrontations.

One of them was Greene’s heated confrontation on Oct. 14 when he was asked to leave a high school football game after waving a Confederate flag. A video of the incident was uploaded to YouTube last month by an account under Greene’s name and was titled: “Police Abuse, Civil Rights Violation at Urbandale High School.”

In it, the man can be heard telling the police he was assaulted and almost mugged while “peacefully protesting.” An officer in the video tells the man, “In the current social climate that we’re in, when you fly a Confederate flag standing in front of several African American people, that’s going to cause a disturbance, whether you intended to or not.”

Denzil Miller, a senior at Hoover High, the school playing Urbandale, said a “murmur” spread along the game’s sideline as people noticed Greene’s flag.

“It was kind of shocking,” said Miller, 18. “It’s not like everyone was getting into a big uproar about it, but everyone noticed.”

The Urbandale Police Department said that they had issued a warning to Greene for the episode. Police also said his daughter attended the school. Court papers say that Greene has a daughter with the same name as a student listed on a roster for the school’s cheerleading squad.

Voluminous court records point to increasing troubles in Greene’s life in recent years, as he went through a divorce, was cited for numerous traffic violations and outstanding debts.

Neighbors say the death of Greene’s father from cancer six years ago hit him especially hard.

Afterward, Greene and his youngest daughter moved in with his mother, Patricia Greene, 66, said Richard and Phyllis Nace, who live across the street from the Greenes.

Court records show in 2014 Greene was accused and convicted of harassment. A man in that case told police that Greene called him the n-word and threatened to kill him.

More recently, Greene had a violent falling out with his mother.

In court documents, police said Greene recorded on video a fight with his mother on Oct. 16, showing his mother yelling at him, grabbing him and hitting him. Both took out restraining orders on each other.

At one point in the fight, Greene told police, his mother tried to rip off the dog tags he wears on his neck belonging to his deceased father, saying to him, “You don’t deserve these.”

After their fight, his mother moved in with a friend in Marshalltown, neighbors said, and Greene had been acting strangely ever since. Last week, for instance, said the Naces across the street, Greene spotted the couple and walked over to hug them without warning. And a few days ago, Greene began moving things out of the house.

Just Tuesday, court officials said, Greene had been in court for a hearing on his mother’s accusations that he had abused her. On Wednesday morning, just hours after the shootings, the court approved a protective order against him.

Wan and Berman reported from Washington. Casey Hynes in Urbandale, Iowa, and Julie Tate, Alice Crites, Emma Brown, Travis Andrews and Abby Ohlheiser in Washington contributed to this report.