A Philadelphia police officer was ambushed and shot multiple times at point-blank range by a gunman who allegedly told cops he did it for ISIS and pledged his allegiance to the Islamic State.

Officer Jesse Hartnett, 33, was driving his marked police cruiser through West Philadelphia around 11:45 p.m. Thursday when 30-year-old Edward Archer walked up to the car and began shooting, officials said.

In what the city’s top cop called an attempted “execution,” the suspect fired at least 13 times, emptying a 9-mm handgun as he walked closer to the car, officials said.

Dressed in Islamic garb and wearing a mask, the man allegedly got so close that the gun was even fired from inside the cruiser’s driver’s side window, authorities said.

"He stated that he pledges his allegiance to Islamic State. He praises Allah, and that was the reason he was called to do this," an official said at a press conference Friday.

The gun used was a stolen police firearm that was taken from a home in 2013, Ross said at a press conference Friday.

"That is one of the things that you absolutely regret the most,” he said. “When an officer’s gun is stolen and it’s used against one of your own.”

Hartnett returned fire and the suspect fled, but was caught a short distance away, according to police.

Ross called the five-year veteran a "a paragon of excellence."

"I can't say enough for his bravery and for how he conducted himself," Ross said.

Hartnett was rushed to Presbyterian Hospital with three gunshot wounds to his left arm. He suffered a broken arm and nerve damage, but underwent surgery early Friday and is expected to survive, according to authorities.

He was wearing his bullet proof vest at the time of the attack, Ross said.

"My brother in law, a police officer in WestPhiladelphia, was shot at 13 times point blank while sitting in his patrol car at a red light last night," she wrote. "But it's harder than that to take down aHartnett. Jesse suffered severe blood loss, broken bone, artery and nerve damage in his arm but amazing no bullets hit him in his head or chest. And he still managed to get out and pursue/shoot at the shooter which aided the other officers in his arrest."

A man who identified himself a police officer who responded to the scene also took to social media to support Hartnett, writing: "Not many people would have survived an ambush like that. He got the drop on you and had every intention of killing a cop.

"Whether it was your training, his lack of training, some divine intervention or a combination of all 3; It simply wasn't your time," he continued. "God was watching over you. You did great last night. You made the 18th district and the entire Department proud of you. You are a hero. January 7th will forever be your alive day. Rest up Jesse Hartnett."

Last night, you were stopped at the red light at 60th and Spruce. You were working solo, probably bored out of your mind...