WASHINGTON -- Congress struggled to clear a two-year budget deal late Thursday and was expected to trigger a temporary government shutdown for a second time this year as the bipartisan proposal encountered delays in the Senate.

The sweeping spending agreement hit resistance Thursday night from Sen. Rand Paul (R., Ky.), whose objections slowed the measure's progress in the hours before the government's current funding expires at midnight. The legislation included a short-term spending bill that would keep the government funded through March 23.

The delays meant the government was expected to close briefly but reopen Friday if the package clears both chambers and is signed by President Donald Trump.

Although the top four congressional leaders negotiated the budget deal unveiled this week, it faced pockets of resistance in the House from conservative Republicans concerned about lifting spending and debt and Democrats worried it would diminish their leverage in an upcoming immigration debate.

The bill had bipartisan support in the House but also opposition on both sides of the aisle. It was expected to face a tight vote, adding uncertainty Thursday night, as GOP leaders worked to flip recalcitrant conservatives. Defense Secretary Jim Mattis spent Thursday calling Republicans personally to encourage them to support the bill because it increases military spending, a GOP aide said

The pact sets overall spending levels, boosting funding by almost $300 billion over the remainder of this fiscal year and the next for both domestic and defense programs. The measure also has another $89 billion in relief for regions rebuilding after last year's natural disasters. Lawmakers would still have to translate that into detailed spending legislation.

Its passage would effectively end one of the most high-stakes fights in Washington, which devolved last month into a three-day partial government shutdown. By ensuring stable government funding, the budget agreement would remove the threat of a shutdown from the Democrats' arsenal, disappointing those who had wanted the minority party to wield it in the coming fight over immigration.

The Senate is expected to begin considering immigration legislation next week, as lawmakers wrestle with the fate of young immigrants known as Dreamers, who were brought to the U.S. illegally by their parents. President Donald Trump in September ended a program shielding them from deportation, but gave Congress until March 5 to hammer out a replacement.

The expected bipartisan support for the budget deal is unlikely to carry into the immigration debate, where each party's base has staked out uncompromising ground. But on Thursday, three of the four top congressional leaders took note of a rare moment of bipartisanship.

This week's long-term budget deal "is a strong signal that we can break the gridlock that has overwhelmed this body and work together for the good of the country," Senate Minority Leader Chuck Schumer (D., N.Y.) said on the Senate floor Thursday.

Republicans lauded the hundreds of billions more the Defense Department would receive under the spending agreement, though some railed over its impact on the federal budget deficit.

"I can't just look the other way because my party is now complicit in the deficits," said Mr. Paul, who withheld his consent to speed up time-consuming Senate procedures Thursday evening and potentially past the midnight deadline.

Mr. Paul's high-profile protest, aimed at rallying his supporters, didn't sit well with other lawmakers ready to pass the legislation.

"I'm not trying to be a namby-pamby here, both sides are right -- you have to spend more money on the military, you have to be mindful of the debt," said Sen. John Kennedy (R, La.). "But we find ourselves in a situation where we have also have a responsibility to keep the government open and a responsibility to fund our troops."

Even after Senate passage, the House would need several hours to debate and pass the bill, where it had split both parties.

Many House Democrats had hoped to use their leverage on spending bills to secure legal protections for Dreamers. Spending bills need 60 votes to clear the Senate, where Republicans hold 51 seats. And with many conservatives expected to balk at the higher federal spending, GOP leaders will need Democratic votes to clear the spending package Friday morning.

"It does diminish our leverage, absolutely," Rep. Juan Vargas (D., Calif.) said of passing the budget deal, which he planned to oppose. "I don't see how it doesn't."

Activists have pushed Democratic leaders to use their leverage over the spending bills to take a stand on immigration. House Minority Leader Nancy Pelosi (D., Calif.) spoke for eight hours on the House floor on Wednesday, advocating for the young illegal immigrants and setting a record for the length of the speech. She received a standing ovation when she walked into a caucus dinner Wednesday night, but some Democratic lawmakers said Mrs. Pelosi's speech may have misleadingly broadcast that their sole ambition is to resolve the immigration debate.

"It may have once again reinforced with the American public that that is our singular priority, but I think that is not really the case," Rep. Marcia Fudge (D., Ohio) said of Mrs. Pelosi's speech. Ms. Fudge said she planned to vote for the budget deal, which she said contained "almost everything that I wanted."

Democrats this week began more openly questioning the wisdom of their leaders' attempts to use their leverage on spending bills to try to secure legal protections for the Dreamers.

"We weren't going to get DACA through the budget process no matter what, so yeah we can scream and yell and Nancy can get on the floor for eight hours and I congratulate her for doing that," said Rep. John Yarmuth (D., Ky.), referring to the Deferred Action for Childhood Arrivals program, "but it still wasn't going to get us a resolution."

Senate Majority Leader Mitch McConnell (R., Ky.) promised an open debate over the fate of the young undocumented immigrants. Mrs. Pelosi said she wanted the same commitment from House Speaker Paul Ryan, who has said he would only bring a bill to the House floor that had Mr. Trump's support. But on Thursday, Mr. Ryan said he was confident they could find a bipartisan bill that the president would back.

"I know that there is a real commitment to solving the DACA challenge in both political parties -- that's a commitment I share," Mr. Ryan told reporters, using unusually conciliatory language. "Please know we are committed to getting this done."

Meanwhile the bill also faced opposition from conservative Republicans, who objected to its increased spending and suspension of the debt limit through March 1, 2019. On Wednesday night the House Freedom Caucus, a group of roughly three-dozen House conservatives, took an official position against the budget deal.

"We're spending more money than we ever spent in the Obama era, said Rep. Jeff Duncan (R., S.C.), a member of the Freedom Caucus.

--Nick Timiraos contributed to this article.

Write to Natalie Andrews at Natalie.Andrews@wsj.com and Kristina Peterson at kristina.peterson@wsj.com