A gun-toting madman and an innocent bystander were fatally shot during a chaotic West Philadelphia shootout that also left two cops and three civilians wounded Friday evening, authorities said.

The unidentified shooter walked up to Sgt. Sylvia Young’s squad car in the Walnut Hill neighborhood around 11:20 p.m. and shot her as many as eight times through an open window.

Young, a 19-year department veteran, miraculously survived thanks to her protective vest and was listed in stable condition at an area hospital, according to Police Commissioner Richard Ross.

Ross said a note believed to be written by the shooter was recovered near Young’s car. The twisted letter allegedly contained rambling anti-police rhetoric and even named a parole officer as a specific target.

After shooting Young, the suspect fled and began shooting at random into a nearby bar, striking a security guard in the leg. As police descended on the scene, the suspect grabbed a woman and used her as a human shield before shooting her in the leg and running off again.

As he ran, the suspect fired off several rounds, striking a man and a woman sitting in a parked car. The pair were rushed to a hospital, where the woman was later pronounced dead and the man remained in critical condition.

Ed Miller, a campus cop from the nearby University of Pennsylvania, joined two other officers in chasing after the depraved shooter. They eventually cornered him in an alley, where he was shot and killed. Miller was wounded during the brief exchange of gunfire but was expected to survive. Police flooded the area early Saturday and all public transportation was shut down as cops hunted a possible second suspect.