The incident happened at 12:45 a.m. Tuesday in the 6400 block of Ditman Street.
Police first received a report of a man with a gun at that location.
Two officers en route to the scene heard a description of the suspect and remembered seeing someone fitting that description on a block they had just passed.
They turned their cruiser around and spotted the suspect, identified as 29-year-old David Ellis of Frankford, at Magee and Torresdale Avenues.
See photos from the shooting scene
Police say Ellis immediately pulled out a weapon and fired at the officers.
The urgency of the situation could be heard over police radio.
1st Officer: 1500. Shots fired! Shots fired!
Dispatch: 6401 Ditman, assist the officers. Shots fired. 6401 Ditman.
Officer Stephen Korpalski and three other officers shot back. Korpalski was grazed in the head.
He calmly reported his situation.
Ofc. Korpalski: 1500, I'm hit.
He was picked up by another officer and rushed to Albert Einstein Medical Center, where he was listed in stable condition.
Officers described the scene on police radio.
Officer: They're scooping him. They're scooping him. They're taking him.
2nd Officer: 1524, I have the shot officer. I'm going to Einstein.
One of the officers rode in the back with his wounded comrade.
Officer: 34, I'm in the back of the car. The officer is okay right now. He's talking.
"First thing you hear, shot in the head, so all the alarms go off," Philadelphia Police Deputy Commissioner Richard Ross said. "But we arrived, and he was sitting up talking and asking questions. That was a good thing. But any time you take a head wound, it's always a serious thing."
Korpalski, a 14-year veteran of the department and married father of a 3-week-old child, was treated for his injury and released from the hospital by 7:00 a.m.
David Ellis was hit several times. He was rushed to Aria Torresdale Hospital, where he was pronounced dead.
Investigators say Ellis has at least eight prior arrests, including weapons charges.
"He has a pretty violent history, robbery, sexual assault, violations of the Uniform Firearms Act, narcotics," Philadelphia Police Commissioner Charles Ramsey said.
His weapon was recovered at the scene.
Police have video surveillance from the scene that may help with their investigation.
The District Attorney's office and Internal Affairs are investigating.