PHILADELPHIA -A gunman who opened fire on police Wednesday as they were serving a drug warrant in Philadelphia, wounding six officers and triggering a standoff that extended into the night, is in police custody, authorities said.

Philadelphia police Sgt. Eric Gripp said early Thursday morning that the man was taken into custody after an hourslong standoff with police.

The shooting began around 4:30 p.m. as officers went to a home in a north Philadelphia neighbourhood 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.

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 neighbourhood. 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 day care.

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."

Loading... Loading... Loading... Loading... Loading... Loading...

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

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

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

Philadelphia Mayor Jim 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," Kenney said.