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, US Hartnett left his vehicle and was able to return fire, striking the gunman three times.
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, Ross said.
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.
US Archer's mother, Valerie Holliday, said he is mentally ill and had suffered multiple head injuries, the Philadelphia Inquirer reported.
"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."
Holliday also told the Inquirer that he had been a devout Muslim "for a long time".
After the shoot-out, US 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," US Ross said. "This could have easily been a police funeral."
US Ross said US 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.