A Brooklyn architect who was sentenced to 15 years in prison for admitting he tried to join a Pakistani terrorist group will be allowed to retract his guilty plea and have the controversial case reopened, Brooklyn court papers show.

Judge John Gleeson permitted Agron Hasbajrami to recant because federal prosecutors belatedly revealed that they had used warrantless wiretaps in order to build a case against the Albanian-born US citizen.

Gleeson ruled that Hasbajrmai should have the right to contest that surveillance.

Hasbajrami was busted at JFK in September 2011 as he tried to board a flight to Turkey.

The feds claimed that the architect was radicalized by jihad-preaching websites and was planning to join a terror group in Pakistani borderlands.

He pleaded guilty to the raps and apologized at his sentencing last September before Gleeson blasted his murderous ambitions.

“You came to Brooklyn and decided you wanted to kill Americans,” the judge said, adding that he would have slammed Hasbajrami with more time if it weren’t for a 15-year limit on his sentence.

But more than a year later, Hasbajrami’s case has been thrown wide open once again.

After initially indicating that their surveillance on Hasbajrami had been drawn from conventional wiretaps, the feds acknowledged — after his plea — that they made use of a controversial intelligence program known as FISA that allowed wiretaps without a warrant.

In allowing the plea change, Gleeson said that Hasbajrami could have conceivably fought his case at trial based on that information.

“The government’s misleading pre-plea notice in this case prevented Hasbajrami from knowing about the availability of this legal argument,” Gleeson wrote in his decision.

The judge did not express an opinion on the constitutionality of the warrantless wiretaps, but said Hasbajrami had the right to know that they had been used against him.

“But at a minimum, it is the kind of argument that a criminal defense attorney would want to make in this sort of case,” he wrote.

But Hasbajrami is taking a risky roll of the dice in pushing to vacate his prior plea and sentencing. He faces up to 60 years in prison if convicted of the charges against him at trial.

Gleeson notes in his decision that Hasbajrami’s own lawyer, Steve Zissou, counseled him against seeking a plea change.