(AP)—Democratic opposition on Thursday led to the defeat of a House Republican bill that would have granted more visas to foreign science and technology students but would have eliminated another visa program that is available for less-educated foreigners, many from Africa.

Democrats, including members of the black and Hispanic caucuses, voiced support for allowing more talented foreign students to stay and work in the United States. But they objected to doing that at the expense of others seeking residence in the country.

The bill would have given up to 55,000 green cards a year to doctoral and masters graduates with degrees in science, technology, engineering and mathematics, known as STEM fields. It would have eliminated the Diversity Visa Lottery Program that makes visas available to those from countries with low rates of immigration.

"We must start to take advantage of our status as a destination for the world's best and brightest," said House Majority Leader Eric Cantor.

The STEM Jobs Act had the strong support of U.S. high-tech companies who have been frustrated by watching highly trained foreign students leave the country and work for non-American competitors because they are unable to obtain permanent residence visas.

The House Judiciary Committee said foreign students now receive nearly 4 out of every 10 master's degrees awarded in STEM fields, but that only 5 percent of immigrants are selected based on their skills and education. "This bill makes our immigration system smarter by admitting those who have the education and skills America needs," said committee chairman Lamar Smith.

Those seeking a green card under the bill would have to have received a doctorate or masters degree from an eligible U.S. university in computer science, engineering, math or the physical sciences other than biological sciences. The applicants would also have to agree to work for at least five years for the employer petitioning on his or her behalf. The company must also show there are no qualified Americans for the job.

Democrats said there was a real need to grant more STEM visas but accused Republicans of offering a partisan bill that would make them look more immigration-friendly before the election.

"It pains me greatly that I cannot support this bill," said Rep. Zoe Lofgren, whose district in northern California includes high-tech companies and who has been a leading advocate for more STEM visas. "Although this bill ostensibly seeks to increase STEM visas, it appears to have another, in my opinion, more sinister purpose, to reduce legal immigrant levels."

The black, Hispanic and Asian-Pacific American caucuses put out a joint statement opposing the bill because of its elimination of the Diversity Visa program. In recent years about half the visas granted under that program have gone to residents of African nations. "It appears Republicans are only willing to increase legal immigration for immigrants they want by eliminating legal immigration for immigrants they don't want," the caucuses said in their letter.

Smith said the program has invited fraud and poses a security risk from terrorists seeking entry into the country.

The Republican majority brought up the bill under a procedure that limits debate and doesn't allow amendments but requires a two-thirds majority for passage. The vote was 257-158, 20 votes short of what was needed.

Democrats expressed hope that Congress, which leaves on Friday and won't be back until after the election, would still be able to reach a consensus on a STEM visa bill this year.

Sen. Chuck Schumer, who unsuccessfully tried to negotiate a compromise bill with Smith, on Tuesday introduced his own bill that would increase STEM visas without reducing visas provided for other programs.