A federal immigration judge has ended deportation proceedings against a Modesto man who spent months in custody, despite his claim that he is a U.S. citizen.

Douglas Centeno, 31, was released from an immigration jail in April after a Chronicle story attracted fresh attention from immigration officials to his case. Now the government has abandoned its efforts to deport Centeno, accepting the evidence that he is, in fact, a U.S. citizen.

Centeno's case is the latest example of an increasingly common problem, legal experts say: People wind up in immigration detention for months, or years, trying to assemble evidence to show that they don't belong there in the first place.

"If it's not clear whether you are an immigrant or a citizen, the system is set up to detain you," said Holly Cooper, a professor at the UC Davis School of Law. "The default is, you are an alien, and then from a remote detention facility you have the burden to get documents, sometimes from people who are deceased."

Citizenship is one of the most complex areas of law, Cooper said. Some people born abroad inherit U.S. citizenship from a parent or grandparent; others gain it as children if their parents naturalize. Sometimes that citizenship is difficult to trace or document.

That was what happened for Centeno, according to his attorney, Sin Yen Ling of San Francisco's Asian Law Caucus. Born in Nicaragua, Centeno arrived in the United States legally as a 2-year-old. When he was 16, his father became a naturalized U.S. citizen, and Centeno automatically derived citizenship as well, though he never obtained a naturalization certificate to prove it.

Legal immigrants who have been convicted of certain crimes face deportation; citizens do not. And in recent years, local law enforcement agencies have increased their cooperation with immigration officials, handing over potentially deportable aliens.

Centeno landed in the custody of Immigration and Customs Enforcement agents in December after serving time for assaulting an officer.

Centeno, who suffers from schizophrenia and bipolar disorder, was walking down the street talking to himself when police stopped him, according to Ling. Centeno asked police to take him to a mental health center, and when he was refused, he had a psychotic episode and struck out, she said.

"Unfortunately, it snowballed into him being put in deportation proceedings," said Ling. "It was a huge mishandling of someone with mental health problems."

Centeno was locked up for four months. After ICE released him from custody, Ling asked the immigration court to terminate the deportation proceeding against him.

Though Centeno is still waiting for the government to issue his citizenship certificate, ICE did not oppose the termination. On May 12, Judge Lawrence DiCostanzo ended the deportation case, noting that the evidence appears to show that Centeno is a citizen.

"It's a great ending for Douglas," said Ling. "But the consequence of this broken system is that it wrongfully deports U.S. citizens. We need Congress or the Obama administration to fix the system. Advocates like us can push the envelope, but we're chipping away one case at a time."