A suspect is in custody in Philadelphia after an hourslong standoff and shootout that left six officers shot and another injured in a related vehicle crash, authorities said. Two officers and three other people who had been trapped in the building with the shooter were freed after several hours.

Philadelphia District Attorney Larry Krasner identified the suspect as 36-year-old Maurice Hill. The alleged gunman surrendered shortly after midnight. Philadelphia Police Commissioner Richard Ross told reporters it was teargas that got the suspect to give up.

Attorney Shaka Johnson said Hill called him to the scene of the standoff while he was barricaded inside. "Maurice called me in a panic, obviously," Johnson told CBS Philadelphia. "He did not want this to end violently and he really was sort of taking an opportunity to speak his peace. I told him, 'You gotta surrender, man."'

Get Breaking News Delivered to Your Inbox

Hill wasn't injured in the shootout, according to Johnson, who added that Hill was brought to a hospital to be checked out, then released with officers surrounding him overnight. Krasner said during a press conference Thursday that Hill would face charges of attempted murder and aggravated assault among others.

CBS News has learned Hill has a long criminal history.

Maurice Hill Philadelphia Police Department

Police had initially responded around 5 p.m. on a narcotics warrant and things "went awry almost immediately," Ross said.

The commissioner said at a nighttime press conference that police were trying to communicate with a "single male" suspect. Police spokesperson Eric Gripp tweeted earlier that police are "imploring him to surrender and avoid further injuries."

Gripp tweeted that children from nearby day care centers were evacuated.

Gripp said the officers were transported to local hospitals with non life-threatening injuries. Philadelphia police said at 11 p.m. that all the officers who were shot had been released from the hospital. One officer who was injured in a vehicle crash related to the incident remained in the hospital.

Four women who were escorted from the Nicetown-Tioga neighborhood told CBS Philadelphia they were on the second floor of the building with the suspect. "I thank God for these cops," one woman said. Police urged residents to avoid the area.

Sources told CBS Philadelphia it appeared the suspect live-streamed at least part of the shootout. At least one male suspect was believed to be barricaded inside a building, CBS Philadelphia reported.

Officers gather for crowd control near the shooting in Philadelphia on August 14, 2019. Matt Rourke/AP

At least one officer was shot in the head, one was shot in the leg and another in the hand. It's unclear where the other officers were shot. Several of the officers shot were taken to Temple University Hospital. The university said the Health Sciences Center had been on lockdown for several hours, but it was lifted by 7 p.m.

Jericka Duncan contributed to this report.