Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A suspect was captured Wednesday morning in the "ambush-style attacks" of two Des Moines-area police officers slain while sitting in their patrol cars, Iowa authorities said.

Scott Michael Greene, 46, surrendered without incident in nearby Dallas County amid a manhunt several hours after the early-morning shootings, said Sgt. Paul Parizek, a Des Moines police spokesman.

After his capture, Parizek said Greene was taken to the hospital for "some kind of flare-up of an existing medical condition," and charges were pending.

Scott Michael Greene, of Urbandale, Iowa. Des Moines Police Department via AP

Police were still investigating what provoked the killings.

"We’re very relieved right now that he’s in custody and that they were no other police officers hurt or civilians," Parizek said at a news conference.

"We absolutely didn't think it would happen here," he added.

The slain officers were identified as Justin Martin, of the Urbandale Police Department since 2015, and Anthony Beminio, a sergeant with the Des Moines Police Department since 2005.

Urbandale Police Chief Ross McCarty said they were seeking a warrant to search Greene's home in Urbandale, a Des Moines suburb.

A law enforcement official told NBC News the suspect has "a history of problems and mental issues and was in dire straits."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Earlier, police described Greene as armed and dangerous, and said he posed a “clear and present danger to police officers."

Greene was arrested at least four other times, Iowa court records show: in 2001 for assault causing bodily harm, which was dismissed; in 2010 for operating a vehicle while intoxicated, which was dismissed; in 2014 for interference with official acts, for which he paid a fine, and harassment in the second degree, for which he received suspended jail time.

Parizek said this latest incident happened without warning and that there was nothing either could have done to save themselves while they sat in their cars.

There did "not appear that there was any interaction between these officers and the coward who shot them," he earlier told reporters.

Parizek added that his colleagues were traveling in pairs for their own safety.

"These were our friends. They were our co-workers," said Parizek, adding, "We’re heartbroken."

In an earlier statement, the Des Moines Police Department said the first officer was found dead at around 1:06 a.m. CT (2:06 a.m. ET) in Urbandale, which also has its own force. That officer was identified as Martin.

Between 15 and 30 rounds were fired at his patrol car, McCarty said. The weapon is believed to be a .223 caliber gun.

From left, Officers Tony Beminio of the Des Moines Police Department and Justin Martin of the Urbandale Police Department. Des Moines Police; Urbandale Police

A second officer's body was located in Des Moines at 1:26 a.m. CT (2:26 a.m. ET), authorities said. The officer, Sgt. Beminio, died shortly after being taken to the hospital.

"The shootings appear to have been ambush-style attacks," the police statement said.

It added that “suspect information is being developed at this time.”

The Urbandale shooting took place near Urbandale High School, and the school district announced Wednesday it was canceling classes.

The local community was already mourning the loss of two other Des Moines officers who died in a car crash while on duty on March 26.

“I don’t even know where to begin, how bad this year is," Parizek added.

He also referred to tensions across the country and that some people have "not-so-positive views of law enforcement."

The July 7 sniper killing of five officers in Dallas during a peaceful protest highlighted the deadly danger many officers face at work on a daily basis.

"An attack on public safety officers is an attack on the public safety of all Iowans," Gov. Terry Branstad and Lt. Gov. Kim Reynolds said in a statement. "We call on Iowans to support our law enforcement officials in bringing this suspect to justice."

Attorney General Loretta Lynch said the Justice Department will be available to assist in the investigation into the attacks, and cautioned others against ratcheting up "tension and mistrust" between law enforcement and communities.

"I know that while we do not yet know what led the perpetrator to commit these awful crimes, many will be nevertheless be tempted to read a message or motive into this assault," she said. "But let me be clear: there is no message in murder. Violence creates nothing; it only destroys."