A California man who spent 14 years behind bars for plotting a terrorist attack in the United States while attending a training camp in Pakistan had his conviction overturned Tuesday.

U.S. District Judge Garland E. Burrell Jr. ruled that Hamid Hayat, a cherry picker from the community of Lodi in California's Central Valley agricultural heartland, was ineffectively represented by an inexperienced defense attorney.

Federal prosecutors were reviewing the decision and did not immediately say if they'll seek a retrial for Hayat, who has already served more than 14 years of a 24-year sentence for providing material support to terrorists and lying to FBI agents.

Members of Hayat's new legal team – it was led by the law firm of Riordan and Horgan – said they will seek his immediate release from federal prison in Arizona pending further action.

"Two federal judges have found credible the testimony of multiple witnesses that Hamid could not have committed the crimes of which he was accused. That is effectively a finding of actual innocence," they said in a statement.

'THE VIEW' HOSTS ATTACK TRUMP AFTER 9/11 BILL SIGNING CEREMONY COMMENTS

Investigators initially claimed five men were part of an Al Qaeda "sleeper cell" in Lodi, about an hour south of Sacramento.

But only Hayat, a California native, was convicted of terror-related crimes. Three suspects were eventually deported without charges, while Hayat's father, an ice cream truck driver, admitted to a customs violation after a jury was unable to reach a decision on whether he lied to federal agents about his son's activities.

Burrell agreed with a magistrate judge's recommendation that defense attorney Wazhma Mojaddidi failed to find alibi witnesses who would have testified that Hayat never had time to receive terror training while visiting relatives and getting married in his ancestral village in Pakistan.

But Burrell rejected several other instances where U.S. Magistrate Judge Deborah Barnes found that Mojaddidi had erred.

Mojaddidi, an immigration and family law attorney who was trying her first criminal case, "appeared to independently and ably represent Hayat, and that representation did not appear tainted by a conflict of interest," Burrell wrote.

Burrell presided over Hayat's original trial and previously rejected a defense motion over whether Hayat was properly represented at trial. But he adopted Barnes' finding that Mojaddidi's failure to find alibi witnesses was prejudicial.

BRONX MAN, SUSPECTED OF WANTING TO JOIN TALIBAN, PULLED FROM MIDDLE EAST-BOUND PLANE AT JFK

Barnes heard six witnesses who testified that the longest Hayat was absent from his family's ancestral village of Behboodi while visiting Pakistan with family members between 2003 and 2005 was one week. That directly contracted his purported confession to attending a training camp for three to six months.

CLICK HERE TO GET THE FOX NEWS APP

"Hamid cannot get those 14 years of his life back, but we are relieved to see the case take such a big step forward," Hayat's family said in a statement distributed by the Sacramento Valley office of the Council on American-Islamic Relations.

The Associated Press contributed to this report.