While mourning the victims of a late-night shooting, the US city of Dayton, Ohio also gave thanks for the rapid response of police who killed the gunman in just 30 seconds, averting a tragedy on an altogether different scale.

Connor Betts managed to kill nine people and wound more than 20 when he opened fire with an assault rifle in a neighborhood teeming with revelers just after 1.00 am local time. 

But within less than a minute, the 24-year-old Betts was shot dead himself by police officers who rushed to the scene while on patrol nearby.

Mayor Nan Whaley said: "While this is a terribly sad day for our city, I am amazed by the quick response of Dayton police that saved literally hundreds of lives."

"Think of the damage he did in such a short period of time," said President Donald Trump. "It was horrible, but... it could have been so much worse," he added.

Senior police said that officers were on a routine patrol in Dayton's Oregon district, a historic neighborhood which is famed for its bars, restaurants and theaters, when Betts opened fire.

Although the motive for the killing is still not clear, it was no random act of violence: he was clad in body armor and equipped with a 100-round drum magazine that allowed for prolonged shooting without the need to reload. 

He was also wearing a mask.

During the shooting spree, Betts' sister Megan was among the nine people murdered. 

One witness, Izack Johnson, started recording on his camera phone as soon as he heard the first gunshots, which he initially thought could have been fireworks.

In the footage, which was aired by CNN, the sound of rapid shooting could be heard echoing out across the district before a louder barrage of gunfire that appeared to have been the police response.

The footage lasts barely 20 seconds before the noise comes to a sudden halt. 

"Then I saw people running, cars starting coming out of the intersection, recklessly," Mr Johnson told CNN as he described the panic-riven aftermath.

Dayton Police Chief Richard Biehl said that officers were in the area conducting routine patrols when the shooting began.

"Officers were patrolling the Oregon district during bar closing time and heard gunfire," he said at a press conference in the city.

"They observed a large crowd running away from this gunfire. The officers immediately advanced toward the gunfire and within approximately 20 seconds they engaged the suspect who was actively firing and attempting to enter a crowded liquor establishment.

"The threat was neutralised in approximately 30 seconds of the suspect firing his first shots."

We need your consent to load this rte-player contentWe use rte-player to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences

Police said that Betts had been trying to get into a bar called Ned Peppers that still full with Saturday night party-goers.

"Had this individual made it through the doorway of Ned Peppers, with that level of weaponry, there would have been... catastrophic injury and loss of life," said Mr Biehl.

So stopping him before he could get inside there, where you saw all the people they were running in there for protection, it was essential."

In the press conference, police played a recording of a 911 call made a member of the public. 

"We have an active shooter," said the caller. "He was shooting in the air. People were running and screaming. Active shooter."

Sherrod Brown, who represents Ohio in the US Senate, said that medics who rushed to the scene were also able to limit the overall death toll.

"I believe 20 first responders from the region came in addition to six or seven from the city of Dayton that arrived all within 20 minutes to save lives, so that's what local communities do which come together like this," said Mr Brown.

The shooting in Dayton, a riverfront city of about 140,000 people in southwestern Ohio, followed the mass shooting at a Walmart store in El Paso, Texas, where 20 were killed and 26 others wounded yesterday morning.

US President Donald Trump has ordered flags on all government buildings to be flown at half mast for the next five days to mourn the victims of two mass shootings.

"Our Nation mourns with those whose loved ones were murdered in the tragic shootings in El Paso, Texas, and Dayton, Ohio, and we share in the pain and suffering of all those who were injured in these two senseless attacks," he said in a presidential proclamation.

"As a mark of solemn respect for the victims of the terrible acts of violence ... I hereby order that the flag of the United States shall be flown at half-staff at the White House and upon all public buildings and grounds" until sundown on Thursday 8 August.

President Donald Trump added that "hate has no place in our country".