With an opportunity to return to a more conventional legislative process — funding the government for a fiscal year rather than for months at a time — Republican leaders had thought they had sufficient bipartisan support to pass the bill. The adopted measure funds the government through Sept. 30, 2015.

But an early sign of the headwinds facing the legislation came around noon, when the deal barely cleared a procedural hurdle to allow a vote. In several tense minutes on the House floor, support to move forward on the package seesawed, with Democrats shouting “Call the vote” and Republicans holding it open until they were able to persuade two lawmakers to switch their votes.

House Democrats — who were already trying to strike a delicate balance — found their calculation complicated by the White House, which released a pre-emptive signal that Mr. Obama would sign the bipartisan legislation if it made it out of Congress.

Josh Earnest, the White House press secretary, said the administration agreed with congressional Democrats who were angry about several provisions that affect financial regulations and others that would allow larger political contributions to parties during federal campaigns. But he called the funding bill “a compromise” and said passage of the legislation would be good for the economy and would bolster some of the president’s priorities, including consumer protection, early childhood education and the fight against climate change.

Postponing action on the spending bill until next year would not have been good for either party. Republicans were eager to get the package behind them so they could start 2015 with a fresh agenda. And although Democrats found some provisions of the spending bill objectionable — including a measure that would significantly increase the limits on individual contributions to political parties — the package was negotiated on a bipartisan basis and they probably would have been forced into greater concessions next year.