Several officers injured by suspect firing in shooting in Philadelphia; suspect in custody: Police There's a large police presence and residents are urged to avoid the area.

A gunman unleashed a hail of bullets at Philadelphia police officers Wednesday afternoon, wounding six and sending cops diving for cover behind cars, before barricading himself in a building with several hostages.

The suspect finally surrendered at midnight, about seven hours after the shooting began.

The resolution ended a day marked by frightening violence all caught live by overhead helicopters in the North Philadelphia neighborhood of Tioga-Nicetown as the man fired wildly at police officers, who were seen evacuating injured comrades.

Maurice Hill, 34, has been identified as the suspect, according to his lawyer and law enforcement sources. Hill surrendered peacefully to police, and was seen exiting the building with his hands raised.

The suspect barricaded himself inside a building on 15th Street, police said. The shootout began during a narcotics operation at around 4:30 p.m. when officers entered the home to serve a search warrant and were met with gunfire. Some officers had to escape through windows and two were trapped inside with the shooter for several hours, police said. The trapped officers were safely removed from the home as of 9:30 p.m.

The officers were struck in various parts of their bodies and one had a graze wound to the head. All six officers who were shot have now been released from area hospitals, police said.

Several rounds of gunfire continued for more than an hour, ABC Philadelphia station WPVI reported. Officers repeatedly commanded the shooter to "Come out with your hands up," according to the station.

Hill's lawyer, Shaka Johnson, told ABC News he spoke to Hill during the standoff and organized a call between Hill, Philadelphia District Attorney Larry Krasner and Philadelphia Police Commissioner Richard Ross. Johnson said the call was inconclusive, however, they continued speaking throughout the night.

Eventually, Ross gave Johnson a deadline of 11:45 p.m. to get his client to surrender, he said. Johnson convinced Hill, who was afraid he would be shot, to come out with him present for the arrest.

Johnson said Hill, who he has represented for years, just had a baby and said he did not believe any of the shooting was planned, but things got out of hand.

Ross had spoken at press conference from the scene of the standoff late Wednesday, pleading for the shooter to turn himself in.

"We are trying to talk to this male, trying to let him know that he can end this peacefully now," Ross said. "We have called him multiple times. He's picked up the phone a couple times, but he has not answered.

He said officers have been working with a family member of the suspect in an effort to reason with the shooter.

"Despite several attempts to talk to him -- both on the loudspeaker and on telephone -- we have been not been able to make contact with them thus far," Ross said. "This is a very volatile situation that is still unfolding, so as a result there's only so much I can tell you about what's going on inside of that property."

One woman said she heard over 100 gunshots and saw people running for their lives.

"I heard so many gunshots ... I'm scared," she told WPVI.

Agents from the Bureau of Alcohol, Tobacco, Firearms and Explosives are at the scene to assist, a spokesperson said.

Philadelphia Police Sgt. Eric Gripp urged residents to avoid the area.

Temple University's Health Sciences Center Campus was put on lockdown.

"Seek shelter. Secure doors. Be silent. Be still. Police are responding," the university tweeted.

ABC News' Aaron Katersky and Alondra Valle contributed to this report.