State Department officials said Friday that a computer glitch is forcing them to scrap the results of an annual worldwide lottery for U.S. immigrant visas, meaning tens of thousands of people who thought they were one step closer to legally moving to the United States are out of luck, at least for now.

More than 14 million applicants entered a lottery last fall for one of 50,000 visas distributed as part of the annual Diversity Visa Lottery, designed for people who would otherwise have little chance of legally entering the country. The program doesn’t require applicants to have a family or employer sponsor.

Each year, the State Department selects about 90,000 applicants and trims the list down to 50,000 through an extensive series of interviews, background checks and medical exams.

The lottery has been conducted by computer since its inception in 1994, according to State Department officials.

David Donahue, deputy assistant secretary of state for visa services, said Friday that a computer glitch discovered Thursday prompted the computer program to unfairly select people who submitted applications in the first two days of the 30-day application process, which ended Nov. 3. Applicants began checking for the results of the lottery last week.

“These results are not valid because they did not represent a fair, random selection of the entrants as required by U.S. law,” Donahue said in a video statement posted on the State Department Web site. “We sincerely regret any inconvenience or disappointment this might have caused.”

An in-house software coding error caused the glitch and has been fixed, according to officials who were not authorized to speak on the record.

The State Department will hold a new lottery with the existing pool of applicants and announce the winners by July 15, Donahue said. Applicants do not need to reenter to be eligible, and no new applications will be accepted.

Winners of the erroneous lottery who aren’t selected again will be able to reapply next fall or in subsequent years, officials said.

Robert P. Deasy, director of liaison and information with the American Immigration Lawyers Association, said the news would understandably disappoint would-be immigrants.

“It’s good that it was caught early, rather than further into the process, where more of the steps to emigrate to the United States would have been taken – resigning work, selling property, changing plans, building up hopes,” Deasy said.

Congress established the lottery program to attract people from countries with lower rates of immigration to the United States. Immigrants from countries with higher rates of U.S. immigration — including China, El Salvador, Haiti, India and Mexico — are not eligible for the program.