Speaker Paul D. Ryan arriving to vote on Friday. He expressed support for bringing a debate on immigration to the House floor.

WASHINGTON — President Trump on Friday morning signed into law a far-reaching budget deal that will boost spending by hundreds of billions of dollars and allow the federal government to reopen after a brief shutdown.

In an early morning tweet, Mr. Trump said he had signed the bill, adding “Our Military will now be stronger than ever before. We love and need our Military and gave them everything — and more.”

Mr. Trump’s signature came quickly after the House gave final approval early Friday to the deal, h ours after a one-man blockade by Senator Rand Paul of Kentucky delayed the votes and forced the government to briefly close.

House Democrats, after threatening to bring the bill down because it did nothing to protect young undocumented immigrants, gave Speaker Paul D. Ryan of Wisconsin the votes he did not have in his own party and ensured passage. In the end, 73 House Democrats voted yes to more than offset the 67 Republicans who voted no.

Just before the vote, Mr. Ryan voiced support for bringing a debate on immigration to the House floor — though he did not make a concrete promise, as Democratic leaders had wanted.

With Mr. Trump’s signature, the government will reopen before many Americans were aware it had closed, with a deal that includes about $300 billion in additional funds over two years for military and nonmilitary programs, almost $90 billion in disaster relief in response to last year’s hurricanes and wildfires, and a higher statutory debt ceiling.

It should pave the way for a measure of stability through September 2019 after months of lurching from fiscal crisis to fiscal crisis. Mr. Trump will get to boast of a huge increase in military spending, long promised, but his desire to more broadly reorder the government with deep cuts to programs like environmental protection, health research and foreign aid are dead for now — as is any semblance of fiscal austerity.

Mr. Paul, a Republican, made that final point. Angered at the huge spending increases at the center of the accord, he delayed passage for hours with a demand to vote on an amendment that would have kept in place the strict caps on spending that the deal raises.

“The reason I’m here tonight is to put people on the spot,” Mr. Paul said Thursday night. “I want people to feel uncomfortable. I want them to have to answer people at home who said, ‘How come you were against President Obama’s deficits and then how come you’re for Republican deficits?’”

The shutdown came on the heels of a three-day closure brought about by Senate Democrats last month. As midnight approached, Mr. Paul did not relent, bemoaning from the Senate floor what he saw as out-of-control government spending and repeatedly rebuffing attempts by his fellow senators to move ahead with a vote.

“I think the country’s worth a debate until 3 in the morning, frankly,” he said.

Senate leaders were left helpless.

Senator Rand Paul on Thursday ahead of a budget vote in Washington. He held up the vote in a protest of government spending.

“I think it’s irresponsible,” said Senator John Cornyn of Texas, the No. 2 Senate Republican, lamenting what he described as “the act of a single senator who just is trying to make a point but doesn’t really care too much about who he inconveniences.”

Mr. Paul’s ideological opponents were not buying his fiscal rectitude either. Senator Brian Schatz, Democrat of Hawaii, posted on Twitter: “Rand Paul voted for a tax bill that blew a $1.5 trillion hole in the budget. Now he is shutting the government down for three hours because of the debt. The chance to demonstrate fiscal discipline was on the tax vote. Delaying a vote isn’t a profile in courage, it’s a cleanup.”

The Senate finally passed the measure, 71 to 28, shortly before 2 a.m. The House followed suit around 5:30 a.m., voting 240 to 186 for the bill.

Before Mr. Paul waged his assault on the budget deal, trouble was already brewing in the House, where angry opposition from the Republicans’ most ardent conservative members, coupled with Democratic dissenters dismayed that the deal did nothing for young undocumented immigrants, created new tension as the clock ticked toward midnight.

Representative Nancy Pelosi of California, the Democratic leader, told a closed-door meeting of House Democrats that she would oppose the deal, and said that Democrats would have leverage if they held together to demand a debate on immigration legislation. But she suggested that she would not stand in the way of lawmakers who wanted to vote their conscience.

Pressing the issue further, Ms….