The House passed legislation on Tuesday to fund the government through Sept. 30 and avert a shutdown at the end of the week, in a party-line vote that reflected how Republican fiscal hawks have swallowed their concerns about spending in deference to President Trump.

The move sent the measure to the Senate, where Democrats are facing a political dilemma over whether to support it and hand Mr. Trump wide leeway to continue his assault on federal programs and workers, or oppose it and risk being blamed for a government shutdown.

The bill would keep last year’s spending levels largely flat, but would increase spending for the military by $6 billion. It would slightly decrease spending overall, because it would not include funds for any projects in lawmakers’ districts or states. And it would force a cut of more than $1 billion from the District of Columbia’s budget for the rest of the fiscal year.

The vote was 217 to 213, with only one Republican, Representative Thomas Massie of Kentucky, voting against the legislation. One Democrat, Representative Jared Golden of Maine, voted yes.

G.O.P. lawmakers supporting it and Democrats opposing it gave the same reason: They argued that the stopgap bill gave Mr. Trump latitude to continue his campaign to dismantle and defund major pieces of the federal government through Elon Musk’s Department of Government Efficiency, or DOGE.

In the Senate, Republicans would need the support of several Democrats to push the measure past a filibuster and allow it to pass and get to Mr. Trump’s desk before the March 14 midnight deadline to extend federal spending. Senate Democrats have widely criticized the measure, but some, especially those from swing states, have not ruled out ultimately voting for it.

Many conservative House Republicans have refused in the past to support stopgap funding bills because they lump several spending measures together as a take-it-or-leave-it proposition and keep spending flat without making any cuts. That has forced Republican speakers to rely repeatedly on Democrats for the votes to pass legislation to avoid a shutdown — a strategy that led to the ouster of Kevin McCarthy as speaker in 2023.

But hard-liners who previously balked at voting for temporary catchall spending legislation said on Tuesday that they were more inclined to do so this time as a way of giving Mr. Trump flexibility to continue razing the federal government. That support came after a hard press from the White House. Mr. Trump and Russell T. Vought, his budget director, met with conservative members of the House Freedom Caucus last week and pitched them on the legislation.

“I think for a lot of people back home, they’re wondering, why isn’t this just the same thing that Congress always does?” Representative Warren Davidson of Ohio said. “This is how the president has asked us to fight now, so that they can do what they’re doing with DOGE.”

Meeting with House Republicans on Tuesday morning, Vice President JD Vance maintained that the measure was the best they could do under the circumstances.

“Our vice president made it clear that, ‘Hey, they’ve only been in office six weeks, and so it’s hard to have any different outcome than where we are right now,’” Representative Mark Alford of Missouri said.

Mr. Johnson late last year refused to accept a funding extension that would run through September, insisting on a mid-March deadline that would allow Mr. Trump to put his own stamp on federal spending shortly after taking office. But Republicans have failed to pass any spending bills into law that would do so, leaving them with no choice other than a temporary patch if they want to avoid a shutdown.

That was the basis of Mr. Massie’s refusal to back the legislation, even as Mr. Trump savaged him for opposing it and threatened to recruit an opponent to challenge him in the next primary election. Republican leaders, he argued, always claimed that fiscal reform was right around the corner, only to fall back on stopgap bills.

“Unless I get a lobotomy Monday that causes me to forget what I’ve witnessed the past 12 years, I’ll be a NO on the CR this week,” Mr. Massie wrote on social media, using the shorthand for a continuing resolution to keep funding the government at current spending levels. “It amazes me that my colleagues and many of the public fall for the lie that we will fight another day.”

House Democratic leaders pressed their members to oppose the legislation, contending that it would enable the White House’s effort to drastically reduce federal spending without consulting Congress. Unlike regular spending bills, temporary extensions do not explicitly direct how the federal funding levels that lawmakers set should be allocated.

That would give the Trump administration broader discretion over large sums of money at a time when the president has already moved aggressively to block the government from disbursing funds authorized by Congress for a variety of programs.

House Democrats also said they could not support the measure because it did not protect Social Security, Medicare and Medicaid, although those programs are not funded through the appropriations process.

Representative Jim McGovern, Democrat of Massachusetts, described the continuing resolution as “basically a blank check to Trump and Musk that says, ‘Keep doing what you’re doing, we’re all fine with it.’ No way. No way.”

But Democrats in the Senate emerged from a two-hour closed-door luncheon without a decision on how to handle the bill and seemingly divided over whether to force a shutdown as a display of defiance, or to let it become law.

Asked on Tuesday before the House vote how Senate Democrats planned to proceed, Senator Chuck Schumer of New York, the minority leader, said, “We’re going to wait to see what the House does.”

Carl Hulse contributed reporting.