Philadelphia's mayor commended the city's police force for their bravery during a violent standoff that he said could have turned into a "horrific tragedy" Wednesday night.

"They were brave. They were running towards heavy gunfire," Jim Kenney told a news conference on Thursday. "They were keeping each other safe while being barraged with ammunition."

Kenney's voice quivered as he described seeing officers later bringing children to safety from a daycare they'd been trapped inside during the incident.

"To see our officers carrying little babies, holding kids' hands, and walking them to safety showed me what those men and women are really about — they're about protecting us," he said.

A gunman opened fire on police Wednesday as they were serving a drug warrant in Philadelphia, wounding six officers and triggering a standoff that lasted more than seven hours, extending well into the night. The gunman is now in police custody, authorities said.

The suspect was identified by his lawyer as Maurice Hill, 36.

Philadelphia Mayor Jim Kenney commended police Thursday for the bravery they showed a day earlier when they ran toward gunfire during a standoff in the city's Nicetown neighbourhood. (Matt Rourke/The Associated Press)

Philadelphia Police Commissioner Richard Ross, who spent hours Wednesday negotiating with the gunman by phone, told a news conference Thursday that the suspect had prior arrests, but didn't elaborate.

Ross said the situation that unfolded Wednesday "could have been far worse."

"This was a very dynamic situation, one that I hope we never see again," he said Thursday outside the Philadelphia Police Department, which is in the process of investigating the scene.

The gunman fired more than 100 rounds, but eventually came out of the home early Thursday after police deployed tear gas in the building. He was taken to a hospital for evaluation and placed into custody.

U.S. President Donald Trump and Attorney General William Barr were briefed on the shooting, officials said on Wednesday.

Trump, in a tweet on Thursday, had already pretty much pronounced the suspect guilty.

"Looked like he was having a good time after his capture, and after wounding so many police. Long sentence – must get much tougher on street crime!" said Trump.

Suspect's lawyer praises police handling

Hill's lawyer said his client called him during the standoff, asking for help in surrendering.

Shaka Johnson told WPVI-TV on Thursday that Hill called him around 8:30 p.m. Wednesday, saying he was barricaded in a house and wanted to come out. Johnson said he arranged a phone call for his client with Ross and Philadelphia district attorney Larry Krasner.

Johnson, who praised police for their handling of the situation, said Hill has a newborn daughter and a teenage son, and wanted to see his children again.

Police take the shooting suspect into custody after a lengthy standoff with police. An area lawyer said he was representing the suspect, and identified him as Maurice Hill. (Elizabeth Robertson/The Philadelphia Inquirer via AP)

The shooting began around 4:30 p.m. as officers went to a home in a north Philadelphia neighborhood of brick and stone rowhomes to serve a narcotics warrant in an operation "that went awry almost immediately," Philadelphia Police Commissioner Richard Ross said.

Many officers "had to escape through windows and doors to get [away] from a barrage of bullets," Ross said.

The six officers who were struck by gunfire have been released from hospitals, Philadelphia police Sgt. Eric Gripp said.

'Nothing short of a miracle'

Two other officers were trapped inside the house for about five hours after the shooting broke out but were freed by a SWAT team well after darkness fell on the residential neighborhood. Three people that officers had taken into custody in the house before the shooting started were also safely evacuated.

"It's nothing short of a miracle that we don't have multiple officers killed today," Ross said.

Temple University locked down part of its campus, and several children and staff were trapped for some time in a nearby daycare.

A police officer patrols the block near the home in Philadelphia's Nicetown neighbourhood. Six officers are in stable condition after being injured in a shooting. (The Associated Press)

Police tried to push crowds of onlookers and residents back from the scene. In police radio broadcasts, officers could be heard calling for backup as reports of officers getting shot poured in.

"I was just coming off the train and I was walking upstairs and there were people running back downstairs who said that there was someone up there shooting cops," said Abdul Rahman Muhammad, 21, an off-duty medic. "There was just a lot of screaming and chaos."

Police implored the gunman to surrender, at one point patching in his lawyer on the phone with him to try to persuade him to give up, Ross said.

"We're doing everything within our power to get him to come out," Ross said during the standoff. "He has the highest assurance he's not going to be harmed when he comes out."

Dozens of officers on foot lined the streets. Others were in cars and some on horses.

Police Commissioner Richard Ross Jr. says officers used a bullhorn and involved a family member of the suspect as they tried to negotiate his surrender. (Bastiaan Slabbers/Reuters)

The Bureau of Alcohol, Tobacco, Firearms and Explosives said its agents responded to the scene to assist Philadelphia police.

Kenney said he was thankful that officers' injuries weren't life-threatening.

"I'm a little angry about someone having all that weaponry and all that firepower, but we'll get to that another day," he said.

At Thursday's news conference, the mayor called for U.S. lawmakers to crack down on gun violence, to help police officers and communities.

If they won't take action, they should "step aside," he said.