Duarnis Perez became an American citizen when he was 15, but he didn't find out until after he had been deported and then jailed for trying to get back into the country.

He was facing his second deportation hearing when he learned he was already a U.S. citizen. Still, federal prosecutors fought to keep him in custody.

Last week, a federal judge scolded prosecutors for the mistake.

"In effect, the government is arguing that an innocent man who was wrongly convicted should not be released from the custody of the United States," U.S. District Judge Lawrence Kahn wrote. He ruled that Perez never should have been deported.

Click here to visit FOXNews.com's Immigration Center

The case has gotten the attention of immigration observers, who call it a striking example of the gaps in an overworked immigration system.

Perez became a citizen when his mother was naturalized in 1988 but apparently wasn't aware of it. His lawyer, J. Jeffrey Weisenfeld of New York, declined to release details other than to say that Perez, now in his early 30s, remains in the United States.

"He would like to get on with his life quietly," Weisenfeld said. "It was an unpleasant experience for him."

Perez was deported to the Dominican Republic in 1994 after a drug conviction.

In 2000, he was caught trying to re-enter the United States from Canada. But he wasn't informed he was a citizen until the spring of 2004, after serving three-and-a-half years in prison for that 2000 arrest.

It was not clear why Perez's status wasn't discovered when he first faced deportation. Messages left over three days seeking comment on the case from Immigration and Customs Enforcement in Washington were not returned.

In early 2005, Perez filed a lawsuit to vacate the illegal re-entry conviction. He also has sued the Bureau of Prisons and the Department of Justice, claiming they had no right to imprison him, and against the Legal Aid Society in Albany, which represented him on the illegal re-entry charge.

Immigration watchers wonder if he can sue for being deported in the first place.

"Beyond legality, it's just an issue of common sense and humanity,'" said Daniel Kowalski, a Texas attorney who publishes Bender's Immigration Bulletin, a publication that tracks immigration issues.

U.S. immigration courts handled 368,848 matters in 2005, a 23 percent increase over the 299,474 cases addressed in 2004, according to U.S. Department of Justice's Executive Office for Immigration Review.

A spokesman for the U.S. Citizenship and Immigration Services said the government has no practical way to inform people of their citizenship in such cases because of the complexities involved.

"The responsibility rests fully on the shoulders of the new citizen, so the questions of the citizenship of children are adequately addressed," said Chris Bentley. "Many times, we honestly won't know about it."

Assistant U.S. Attorney Sara Lord, who prosecuted Perez, declined comment when asked if the government would appeal. In a brief, she argued Perez was at fault for not knowing his status, saying he "cannot base his failure to discover the circumstances on the alleged omissions of others."

Estelle McKee with the University of Wisconsin Law School said the responsibility is shared.

"The immigration service has to prove someone is removable. It's their job," she said. "It's remarkable to go through an entire removal process and not know the person is a citizen."