The House rejected a three-week stop-gap bill to keep the Department of Homeland Security fully operating Friday, a major defeat for Speaker John A. Boehner as a midnight deadline loomed to avoid a shutdown of the massive agency.

In a chaotic scene on the House floor, 51 Republicans rebuffed a major last-minute effort by their leadership to salvage the measure. House leaders kept the roll call vote open for almost an hour, long after the official voting time had expired, as they sought to persuade members to change their votes.

The bill's defeat, 203 to 224, tested the ability of the new Republican-led Congress to avoid a government crisis.

Even the Senate’s willingness to quickly accept the stop-gap plan – and the White House commitment that President Obama would sign it into law – was not enough to win Republicans’ support. Nearly all House Democrats opposed the measure, preferring a Senate-passed measure that would have provided funds for the rest of the fiscal year, which ends Sept. 30, the Los Angeles Times reports.

The next step was unclear. The huge Homeland Security Department is scheduled to run out of legal authority to spend money unless both houses of Congress act by midnight. House Majority Leader Kevin McCarthy (R-Bakersfield) warned members they may need to work through the weekend to try to resolve the problem.

If Congress does not pass a new money bill, some of Homeland Security's more than 200,000 employees would be furloughed, but most would be required to work without pay as they guard the nation's borders and ports and run programs such as immigration, customs and airport security.