Ahmed Ferhani, a so-called lone-wolf terrorist serving a 10-year sentence at Attica Correctional Facility upstate, tried to hang himself two weeks ago and is in a coma in a Buffalo hospital.

His lawyer, Lamis Jamal Deek, said Ferhani had written to correction officials and to the Justice Department in Washington to complain of beatings and harassment by guards. A state prison spokesman declined to comment “due to an ongoing investigation.”

It’s hard to feel sympathy for a terrorist, but was Ferhani a terrorist, or did the NYPD manipulate him into plotting a terrorist act? Under then- Commissioner Ray Kelly and his Intelligence Division head, former CIA operative David Cohen, the department sought to make terrorism cases on its own to gain equal standing with the FBI.

The FBI did not participate in Ferhani’s 2011 arrest. Law enforcement sources said then that the bureau questioned the actions of an NYPD undercover officer who befriended Ferhani, a petty criminal with a history of psychiatric problems. The undercover officer then persuaded him to buy guns from another undercover, Deek said.

“They turned a gun case into a terrorism case,” he said.

Deek said Ferhani, of Queens, had repeatedly been institutionalized for harming himself since he was 16.

Ferhani’s arrest was announced by Kelly and then-Mayor Michael Bloomberg, who said Ferhani had plotted to blow up the largest synagogue in Manhattan and kill as many Jews as possible.

Manhattan District Attorney Cyrus Vance indicted Ferhani, the first person charged under a state terrorism law passed after 9/ll. A grand jury rejected the top terrorism count, which carries a sentence of life imprisonment. In 2012, Ferhani pleaded guilty to lesser terrorism charges.

Ferhani’s mother, Kheira, said in a phone interview that the family had come to America from Algeria because of threats by Muslim extremists. “I was a French teacher,” she said from her son’s bedside. “Fundamentalists sent a letter, threatening to kill me. I am a Muslim, but I don’t wear the hijab. Before I retired, I worked at Saks and Bergdorf as a beauty adviser. My children were all raised in America. They have an American mentality.”

She said doctors have told her that even if her son recovers, he may be blind and/or paralyzed. Now she sits by his bedside hoping for a miracle.