After decades of slipping through the cracks, Mario Hernandez, who came to the United States when he was 9, served in the U.S. Army and spent 22 years in the federal prison system, finally received something he thought he already had.

American citizenship.

Hernandez, who lives in Tallahassee, was at the U.S. immigration office in Jacksonville on Wednesday to reverse denials he'd been served during an earlier attempt at getting his citizenship.

"The last time I walked in here, I was treated like dirt," he said while waiting for his case to be called.

By 1:30 p.m. his oath of citizenship had been administered in a cobbled-together ceremony at the Southside office.

"I couldn't be happier," he said.

His first act, he said, will be to get his voter registration card in Tallahassee.

"This is the only country I've known and I am very proud," he said.

A 9-year-old in 1965 when he came here from Cuba with his mother and three sisters, Hernandez was allowed to stay under the Cuban Adjustment Act. He was eligible for a green card a year later and citizenship five years after that, but no one in his family ever applied for those documents.

He was given a Social Security card in California when an employer helped him apply for one, he said.

When he joined the Army, he took what he believed was an oath of citizenship. After a three-year stint, he went on to work and never left the country. He has paid taxes throughout his life and has no criminal record, his attorney said.

It wasn't until after he retired and decided to go on a cruise with his wife, Bonita, that he learned he needed a passport.

He had no paperwork proving his citizenship. The application was denied.

It should have been granted.

When he joined the Army in 1975, the Vietnam War was still in what was considered a "designated period of hostility." That factor qualified Hernandez for citizenship, but the immigration service denied his application in March. His attorney appealed and two continuances followed.

"I think it shows the immigration system is very broken," said Elizabeth Ricci, the attorney who is handling his case. "This is my third case like this."

The others were in 2010 and also involved military service members, she said. With 100,000 immigrants serving in the military, there may be hundreds or more similar cases, Ricci said.

"It's broken all the way around," she said.

Wednesday, Hernandez' fate hinged on another interview with officials at the Jacksonville office of the Department of Homeland Security.

"I'm super nervous," he said before walking inside for a 10 a.m. appointment. "I only slept two hours last night."

Late in the morning he learned he would qualify for citizenship but there were questions about whether he could be given the oath in Jacksonville or would have to wait for a July ceremony in Tallahassee. It was jurisdictional issue involving federal court districts and his residency in Tallahassee.

"I'm less in limbo than I was, but I'm still in limbo," a frustrated Hernandez said as he waited for a decision.

Chief Justice M. Casey Rodgers of the Northern District of Florida in Pensacola eventually gave the green light. Flags were stood up and unfurled inside the Homeland Security office, and Hernandez was naturalized by Lisa Bradley, the field office director.

"Thank you, Lord," he said and hugged Bradley.

The government made a mistake, the department said, when his application was reviewed as a standard application for citizenship and not under the special provisions of military service during a period of hostility.

"Simply put, we decided his application under the wrong section of the law," part of a statement by immigration service spokesman Chris Bentley said.

Hernandez said one of the most painful aspects of losing the citizenship he thought he had was the loss of his voter card.

He had cast votes in major elections across the country since the year Jimmy Carter won the White House. He and his wife have a son who served as a Navy lieutenant in an engineering unit in Afghanistan and a daughter who has worked with immigrant families.

They have four grandchildren.

During his career in the federal prison system, Hernandez was a supervisor and for a time was responsible for aspects of the detention of Timothy McVeigh and Terry Nichols. He also spent about two years with the Bureau of Indian Affairs, he said.

Those jobs can only be held by U.S. citizens, but background checks never showed his lack of citizenship.

Because he voted, he could have been charged with impersonating a U.S. citizen. He won't be.

"I feel like I was reborn here today," he said. "I feel like jumping. I feel like crying."

Times-Union photographer Bruce Lipsky contributed to this report.