The House on Wednesday refused to order the withdrawal of U.S. forces deployed to fight Islamic State militants in Iraq and Syria by the end of the year.

The measure was defeated, 288-139. It would have directed that troops be withdrawn within 30 days of passage, or by the end of the year, if Congress fails to authorize the fight against Islamic State militants.

Rep. Jim McGovern, D-Mass., said the resolution was needed to "force Congress to do its job" and vote on whether to formally authorize military action against Islamic State militants. President Barack Obama requested such a resolution in February, but it has stalled in Congress.

"If we are going to invest a generation or more of our blood and our treasure in this war, and if we're going to continue to tell our armed forces that we expect them to fight and die in these wars, it seems to me the least we can do is stand up and vote to authorize these wars — or we should end them," McGovern said in a fiery speech on the House floor.

McGovern, who co-sponsored the resolution with Reps. Walter Jones, R-N.C., and Barbara Lee, D-Calif., said lawmakers owe it to the American people to vote on a war resolution.

The U.S. military has 3,500 troops in Iraq. The Pentagon has said repeatedly it has no personnel in Syria.

Opponents called the measure dangerous, saying it could lead the U.S. to "walk away" from the region, leaving it more unsettled and increasing the chances of the Islamic State becoming even stronger.

Rep. Ed Royce, R-Calif., chairman of the House Foreign Affairs Committee, said approval of the resolution would be "seen as a no-confidence vote" in U.S. troops. Withdrawal of U.S. troops could lead to mass killings, assaults and the forced sex trade of teenage girls, Royce said.

Rep. Eliot Engel of New York, the senior Democrat on the panel, said he agreed with McGovern that Congress should vote on a war powers resolution. But he said immediate withdrawal of U.S. troops was "no way to defeat ISIS," using an alternate acronym for the militant group.

"It's a difficult fight, but I don't think we should walk away," Engel said.

Gen. Martin Dempsey, chairman of the Joint Chiefs of Staff, said withdrawal of U.S. troops "would be a mistake for obvious reasons."

The U.S. has national security interests within Iraq and also has interest in maintaining credible safe and reliable allies in the region, Dempsey told the House Armed Services Committee on Wednesday.

"Our withdrawal would challenge (that) and put us at greater risk over time," Dempsey said.