From left: Senate Majority Leader Mitch McConnell (R-Ky.), President Donald Trump, and House Speaker Paul Ryan (R-Wis.) in the Roosevelt Room of the White House in Washington, Nov. 28, 2017. With government funding set to expire Dec. 8, Republicans are aiming to buy more time so they can negotiate over a long-term spending package, a task complicated by a deepening feud with Democrats, whose votes they need to secure passage. Doug Mills/The New York Times

WASHINGTON — Republicans are moving toward passing a two-week stopgap measure to avoid a looming government shutdown, but the path in the coming weeks is treacherous, with obstacles on both sides of the aisle as lawmakers push their own priorities, some unrelated to government spending.

With government funding set to expire at the end of Friday, Republicans are aiming to buy more time so they can negotiate over a long-term spending package. The task is complicated by a feud between President Donald Trump and Democrats, whose votes Republicans need to secure passage, and measures on the politically fraught issues of immigration and the Affordable Care Act.

The possibility of a shutdown looms just after Senate Republicans succeeded in passing their sweeping tax overhaul, a moment of triumph for a party that has struggled to produce big achievements despite controlling Congress and the White House. But promises made to secure passage of the tax bill could further complicate negotiations on government funding, and any failure at the fundamental task of keeping the government running would swiftly undercut Republicans’ display of progress.

The threat of a shutdown escalated last week after Trump fired off a Twitter post attacking the top Democrats in Congress, who in turn pulled out of a planned White House meeting, deepening the rift between the parties at a time when they are already at odds over issues like taxes, health care and immigration.

Republicans’ stopgap spending measure would extend government funding through December 22. On Sunday, the Senate majority leader, Mitch McConnell of Kentucky, tried to play down fears about a coming crisis.

“Look, there’s not going to be a government shutdown,” he said on ABC’s This Week. “It’s just not going to happen.”

But the feud between Trump and the top Democratic congressional leaders provided ample cause for concern. The acrimony is a stark change from just a few months ago, when Trump sided with those leaders, Sen. Chuck Schumer of New York and Rep. Nancy Pelosi of California, on a short-term deal to fund the government and increase the debt limit.

Now, the president is in direct conflict with “Chuck and Nancy,” as he has called them, at a time when Democrats have substantial leverage. Democrats can block the stopgap spending measure in the Senate, and Democratic votes could also be needed to get the measure through the House if enough Republicans rebel against it. Any long-term spending package would also need Democratic votes.

Citing the power that Democrats hold under Senate rules, Rep. Trent Franks, R-Ariz., complained last week that his party was being forced, despite having majorities in both houses, to “produce basically a Democrat document.”

“It’s an untenable, unworkable thing, and it’s a hell of a way to run a railroad,” he said.

The stopgap spending measure would provide more time for negotiations between the two parties over raising strict spending caps that were imposed in 2011 as they try to work toward a long-term spending deal for the 2018 fiscal year, which began Oct. 1.

In a deal to raise the limits, defence hawks want a sizeable increase in military spending. But Democrats are pushing to ensure that non-defence spending is increased by the same amount as military spending. Once congressional leaders reach a deal on raising the caps, a long-term spending package can be negotiated. Lawmakers could pass another stopgap spending measure later in December to keep the government open until that long-term package is ready to be voted on.

“We want to keep government open,” Pelosi said last week. “That’s what we are about.” But she emphasized the need to provide an acceptable increase in nondefense spending as part of a deal to raise the spending caps, citing issues like providing funding to address the opioid epidemic.

Lawmakers are also pushing to provide tens of billions of dollars in additional disaster relief in response to Hurricanes Harvey, Irma and Maria. Members of both parties called a request from the White House last month to provide $44 billion in aid insufficient.

Complicating matters further are divisive issues being dealt with on Capitol Hill beyond financing the government. Republicans are closing in on sending their tax overhaul to Trump, a feat that would represent their first major legislative accomplishment of his presidency, and they hope to finish that work by Christmas.

The future of insurance markets under the Affordable Care Act is also the subject of debate, especially after Senate Republicans added to their tax bill a provision that would end the health law’s requirement that most people have coverage or pay a penalty. The Congressional Budget Office has projected that repealing the so-called individual mandate would increase average premiums on the individual market about 10 percent.

A holdout on the tax bill, Sen. Susan Collins, R-Maine, decided to support the legislation in part because McConnell committed to support passage by the end of the year of two measures intended to reduce premiums under the Affordable Care Act, which Collins suggested would mitigate the effects of ending the individual mandate. One of those measures would provide funding for subsidies to insurers that Trump had cut off.

But it remains unclear what other legislation those measures would be attached to, and how such a move would be received by House Republicans who have criticized the subsidies as a bailout for insurers. Lawmakers also need to provide funds for the Children’s Health Insurance Program, whose funding expired at the end of September.

Then there is the issue of immigration. Democrats want to secure a deal to protect young unauthorized immigrants put at risk by Trump’s decision to end Deferred Action for Childhood Arrivals, or DACA, the Obama-era program that shields them from deportation.

Another Republican holdout on the tax bill, Sen. Jeff Flake of Arizona, said in announcing his support for the tax overhaul that he had obtained a commitment from Senate leaders and the Trump administration to work with him to enact protections for DACA recipients.

The spending negotiations provide Democrats with leverage for reaching a deal on that issue. But Republican leaders want to address it separately.