Media playback is unsupported on your device Media caption Footage showed the moment of the attack

A man who shot and wounded a policeman at point blank range as he sat in his patrol car was inspired by Islamic State militants, police said.

Edward Archer, using a stolen gun, fired at least 11 shots at Jesse Hartnett in Philadelphia.

Despite being shot, Mr Hartnett left his vehicle and was able to return fire, striking the gunman three times.

Mr Archer was arrested within minutes and later confessed to police he did it for Islam, officers told reporters.

"He has confessed to committing this cowardly act in the name of Islam," Police Commissioner Richard Ross said, because he believes "police defend laws that are contrary to Islam".

The 30-year-old from Yeadon, Pennsylvania, told police he pledged allegiance to Islamic State.

But there is no evidence that he was working with anyone else, Mr Ross said.

Media playback is unsupported on your device Media caption "I'm absolutely amazed Officer Hartnett is with us today"

Image copyright AP Image caption Officer Hartnett is expected to recover from his injuries

Philadelphia court records show he was convicted of assault in March and was set to begin a prison term. He had also been convicted of forging documents in a nearby suburb.

Mr Archer's mother, Valerie Holliday, said he is mentally ill and had suffered multiple head injuries, the Philadelphia Inquirer reported.

Image copyright Police handout Image caption Archer was shot several times

"He's been acting kind of strange lately. He's been talking to himself . . . laughing and mumbling," she told the newspaper.

"He's been hearing voices in his head. We asked him to get medical help."

Ms Holliday also told the Inquirer that he had been a devout Muslim "for a long time".

After the shoot-out, Mr Hartnett screamed into his radio: "I'm shot, I'm bleeding heavily." He has serious injuries and requires surgery.

"His will to live undoubtedly saved his life," Mr Ross said. "This could have easily been a police funeral."

Mr Ross said Mr Archer's gun was a police firearm that was stolen in 2013.

The shooting happened on the day two men who came to the US as refugees were charged with supporting terrorism - in Texas and California.

A month ago, attacks in San Bernardino, California, left 14 people dead, carried out by a couple inspired by Islamic State.