NEW YORK (AP) — A man accused of building homemade bombs to wage holy war in New York City pleaded guilty Wednesday to a terrorism charge less than a week before his scheduled trial in a rare state-level terrorism case.

Jose Pimentel, wearing a knitted skull cap, softly answered questions and shook his head at times as he acknowledged he’d tried to craft a pipe bomb in 2011, with the idea of using it to make a violent impact on U.S. foreign policy.

He sought, according to a statement a judge read on his behalf, to “try to undermine public support for the wars in Iraq and Afghanistan.”

Pimentel pleaded guilty to attempted criminal possession of a weapon as a crime of terrorism. Authorities have called the case a dramatic example of the threat of homegrown, one-person terrorism plots, but his lawyers have portrayed it as an example of overzealous policing in the years since Sept. 11.

With the plea, Pimentel, 29, was promised a sentence of 16 years in prison. He could have faced a minimum of 15 years to life if convicted. Jury selection had been due to start Monday.

“Today’s guilty plea further supports the fact that, increasingly, the threat of terrorism comes from radicalized local actors living in our community,” Manhattan District Attorney Cyrus R. Vance Jr. said at a news conference.

But Pimentel’s lawyers have suggested he would never have progressed from posting online to trying to make pipe bombs if police hadn’t sent a series of informants to engage with him.

While he admitted his guilt, “the question that will not be answered, at least not in a court of law, is who exactly is recruiting whom in this war” against terrorism, said one of his attorneys, Susan Walsh.

Pimentel, also known as Muhammad Yusuf, is a Dominican immigrant who was raised in the U.S. and converted to Islam around 2004.

He maintained a website with articles praising Osama bin Laden, describing Sept. 11 victims as legitimate targets and listing reasons to “nuke the USA,” prosecutors said in court papers. He repeatedly clashed with his former wife because of his militant beliefs about Islam, and his mother had thrown him out of her apartment over his views, prosecutors said.

His vitriol deepened in 2011, when he was recorded talking about assassinating a judge, killing returning soldiers and bombing a police station or the George Washington Bridge, officials said; he also talked about targeting Jews, Assistant District Attorney Deborah Hickey said. He was arrested that November as he assembled bombs from clocks, Christmas tree lights, match-head scrapings and other items acquired at dollar shops and hardware stores, prosecutors said.

One informant and an undercover officer had gotten nowhere with Pimentel, Walsh and fellow Pimentel lawyer Lori Cohen said. But then police sent another informant, a fellow Hispanic Muslim convert who smoked joints with Pimentel while they talked about jihad, accompanied him to buy bomb makings and opened his apartment to Pimentel to put the materials together.

“If you work on someone with professional witnesses, if you acquiesce to marijuana use, you wear people down,” Walsh said last month.

Vance said he was comfortable with the way the investigation was conducted.

The defense had indicated his trial would examine the New York Police Department’s intelligence-gathering on Muslims, which came under scrutiny in stories by The Associated Press that showed how the department infiltrated Muslim student groups, put informants in mosques and monitored sermons as part of a broad anti-terrorism effort.

Vance said prosecutors offered the plea deal to secure a significant sentence without the uncertainties of a trial. Pimentel’s lawyers said he took the offer to avoid the possibility of life in prison.

Entrapment defenses, or arguing that police induced crime, face a high legal burden. It’s not enough to show that police or their agents created an opportunity for law-breaking; a defendant has to convince jurors that police used methods that risk getting an innocent person to commit a crime.

Most terrorism cases are federal, but Pimentel was charged under a New York state law passed shortly after Sept. 11 and seldom used since.

One case involved a Bronx gang leader whose conviction was overturned when appeals courts said his crimes weren’t what the law envisioned.

In another, Vance charged two men with plotting to blow up synagogues. Both pleaded guilty. One is serving 10 years in prison, and the other is serving five.

After Pimentel’s arrest, two law enforcement officials said the FBI had passed on his case because agents felt he wasn’t inclined or able to act without the informant’s involvement; the officials were not authorized to speak about the case and spoke on condition of anonymity.

Vance and Police Commissioner William Bratton said Wednesday that state charges were appropriate in Pimentel’s case.

“There are some who suggest that only federal agencies should handle terrorism cases, or that the terrorism threat from radicalized citizens is, perhaps, overstated,” Vance said. “I strongly disagree.”

___

Associated Press writer Tom Hays contributed to this report. Reach Jennifer Peltz on Twitter @ jennpeltz.