In a statement, Chris Bentley, a spokesman for the immigration agency, said it apologized for handling Mr. Hernandez’s application as a regular naturalization case rather than a military one.

“As soon as this error was brought to our attention, we immediately reopened the case,” Mr. Bentley said, “and this morning, after a thorough review of the case with Mr. Hernandez, we were able to approve his naturalization application.”

It turns out that Mr. Hernandez, despite having voted in every major election since Jimmy Carter’s in 1976 and working for two state agencies and two federal agencies, including as a longtime supervisor for the Bureau of Prisons, was not even a United States resident. Several federal background checks never turned up his immigration status.

A Cuban refugee who arrived here as a child, Mr. Hernandez was given open-ended parole, which allowed him to live and work in the United States but did not make him a resident. He said he had assumed that his parents filed the paperwork to make him a resident and a citizen. When he enlisted in the Army in 1975, Mr. Hernandez said he was given what he thought was a citizenship oath. But when he recently retired and decided to take a cruise, he could not find any trace of the naturalization papers he needed to get a passport.

Elizabeth Ricci, his lawyer, said his situation was an example of how immigration cases, even clear-cut ones involving an Army veteran and a federal employee, could go awry within the immigration agency’s bureaucracy.