Updated

House Republicans failed Thursday in their efforts to block President Obama's decision to close the detention facility at Guantanamo Bay, but lawmakers still moved ahead with legislation that opposes the president's plans.

While debating a bill to fund the Justice Department, lawmakers initially defeated an amendment by Rep. Jerry Lewis, R-Calif. to ban the government from spending any money to close the prison by a vote of 216-212. After a rare legislative procedure triggered a recount, it was defeated again, 213-212.

In the House, some 40 Democrats voted to outlaw funding to close the prison. Only two Republicans voted against the proposed ban.

But a provision in a 2010 spending bill also puts restrictions and reporting requirements on the transfer of Guantanamo detainees to the United States and elsewhere. The bill was set for a vote later Thursday.

Already this week, the House showed its defiance of Obama's goal of shutting down the facility by approving a $100 billion war-spending bill that stipulates that it will not allow the use of federal money to close Guantanamo in the final months of this budget year. That bill is expected to be passed by the Senate soon.

Both the House and Senate want to impose strict requirements on the administration before current detainees at Guantanamo can be transferred to the United States, U.S. territories or third countries.

The Obama administration has already transferred one suspected terrorist to New York to stand trial. Another nine have been transferred to other countries and the Obama administration is negotiating with foreign leaders to accept Guantanamo detainees.

The bill before the House Thursday prohibits the release of detainees into the United States during the 2010 budget year. It would allow the transfer to the United States of detainees for prosecution or detention only after Congress has had two months to read a White House report on how it plans to shut the detention facility and disperse the inmates.

The House bill also requires the Obama administration to notify lawmakers of any plans to transfer detainees to other countries.

The Obama administration had requested $60 million for the Justice Department to carry out its role in the closure.

Also on Wednesday, that House Armed Services Committee approved a measure, offered by Democratic chairman Ike Skelton of Missouri, to restrict the transfer of detainees. It states that no detainee can be transferred without the president presenting a plan dealing with possible dangers the detainees pose and requires the president to consult with governors or the chief executives of territories on proposed transfers.

The $64.4 billion spending bill funds Commerce, Justice and Science department programs at an amount nearly $7 billion above for the current fiscal year ending in September. Much of that goes to the Census Bureau, which will see its budget jump more than $4 billion, to $7.4 billion, as it prepares for the 2010 census.

The vote kicked off an ambitious effort by House Democrats to pass all 12 spending bills before Congress leaves for its August recess and avoid the budgetary standoffs that have become common in recent years.

Last March, President Obama signed a massive $410 billion "omnibus" that belatedly funded non-defense programs across the federal government. That catchall bill was needed because of the inability of the George W. Bush administration and the Democratic-controlled Congress to reach agreements on separate spending bills.

The House got off to a rocky start, with Democrats, confronted with more than 100 Republican amendments, breaking with tradition and, to the outrage of Republicans, limiting the number of amendments that could be offered and restricting the time spent on each amendment.

"There was a very real fear on our side that the process could have degenerated into a drawn-out battle," jeopardizing efforts to complete the bills on time, Rules Committee chairman Louise Slaughter, D-N.Y. said.

"I think the majority is making a big mistake," said Rep. Lincoln Diaz-Balart, R-Fla. "We're witnessing a sad page in the history of this body."

FOX News' Chad Pergram and The Associated Press contributed to this report.