WASHINGTON — Congress approved a $300 billion, two-year spending bill and an additional $90 billion in aid for victims of hurricanes and California wildfires early Friday and President Trump signed it, ending a brief partial shutdown of the federal government.

The Senate voted 71-28 for the legislation after an hours-long delay engineered by Sen. Rand Paul, R-Ky., who complained that the bill’s vast increases in military and domestic spending would raise a deficit already likely to be swollen by a tax bill that promises to add $1.5 trillion to the government’s debt over a decade — a measure Paul voted for.

LATEST SFGATE VIDEOS

Now Playing:
  • Now Playing
    East Area Rapist's decade-long spree San Francisco Chronicle
  • Multiple pods of killer whales in Monterey Bay Monterey Bay Whale Watch
  • Steph Curry during his post-practice shooting session Connor Letourneau
  • Steph Curry during his post-practice shooting session San Francisco Chronicle
  • Drone video of killer whales in Monterey Bay Monterey Bay Whale Watch
  • Killer whales in Monterey Bay seen from the Princess Monterey Princess Monterey Whale Watching
  • Killer whales in Monterey Bay Monterey Bay Whale Watch
  • Suspect Arrested in Golden State Killer Case New York Times
  • Smoked Salmon Sandwiches With Finger Lime Aioli Sarah Fritsche
  • Trump bushes 'dandruff' off of Macron's shoulder San Francisco Chronicle

“My party is now complicit in the deficits,” Paul said.

At 5:30 a.m. EST, the House followed the Senate’s lead, passing the spending bill by a vote of 240-186. The “no” votes included conservative Republicans upset about deficits and liberal Democrats who wanted the bill to be attached to protections for undocumented immigrants brought to the U.S. as children. They face deportation starting next month after Trump ordered an end to the Deferred Action for Childhood Arrivals program, or DACA.

The subject of months of partisan standoff, the 652-page bill was negotiated by Senate and House leaders from both parties and announced by Senate Majority Leader Mitch McConnell, R-Ky., and Minority Leader Chuck Schumer, D-N.Y., Wednesday. More than half the money, $165 billion, goes to the military, and $131 billion to domestic programs, lifting budget caps put in place in 2013.

Trump signed the bill Friday morning, declaring in a tweet, “Our Military will now be stronger than ever before. We love and need our Military and gave them everything — and more. First time this has happened in a long time. Also means JOBS, JOBS, JOBS!”

The new legislation would put a halt to the five stopgap funding emergencies that have plagued the Republican-controlled Congress since the fiscal year ended last September. Unable to pass long-term bills, Republicans have relied on stopgap measures to keep the government open for a few weeks at a time and leading to funding crises as each new deadline approached. The latest expired Thursday at midnight.

It was unclear how the belated congressional passage would affect services Friday morning by government agencies that were shuttered for three days last month under an earlier budget standoff. Vital services such as military operations, air traffic control and mail delivery are unaffected.

The disaster package in the budget bill includes funding and special tax provisions that would apply to all federally declared wildfire disasters in California from Jan. 1, 2017, to Jan. 18 of this year, covering both the Wine Country fires and the winter fires in Southern California. The vast majority of the $90 billion is for damage from three hurricanes that struck Texas, Florida and Puerto Rico last fall.

Also tucked in the bill is $200 million for nine declared fishery disasters from Alaska to California dating to 2014. Reps. Jared Huffman, D-San Rafael, and Jackie Speier, D-Hillsborough, have been urging approval of funds to aid fishermen affected by the 2015-16 closure of the Dungeness crab season and several salmon fisheries going back to 2014. The administration would decide how to allocate the money.

Although there was never any doubt the Senate would approve the legislation, House passage was uncertain. Many Democrats, led by Minority Leader Nancy Pelosi of San Francisco, opposed the bill because of the refusal of House Speaker Paul Ryan, R-Wis., to promise an open debate on providing legal status to young immigrants. About 690,000 undocumented immigrants who arrived in the United States as minors have been protected from deportation under the Obama administration’s DACA program, which Trump intends to end on March 5.

Pelosi commandeered the House floor for a record eight hours Wednesday, reading stories of the young immigrants and demanding that Ryan permit debate on several immigration bills, allowing the one that gets the most votes to pass, a procedure known as “queen of the hill.” But Republicans, who are in power, typically permit votes only on bills supported by a majority of their caucus.

Pelosi urged Democrats at a closed-door caucus to use their leverage to force an immigration debate by voting no on the spending bill, but stopped short of insisting they hold ranks. She followed at midnight with a letter to Ryan from her and her top lieutenants, Steny Hoyer, D-Md., and James Clyburn, D-S.C. They told the speaker they supported the spending bill but demanded debate on a mostly Democratic-backed immigration bill that would provide legal status for the young immigrants and has 27 Republican co-sponsors, including two San Joaquin Valley Republicans, Reps. Jeff Denham of Turlock (Stanislaus County) and David Valadao of Hanford (Kings County).

“It’s so easy,” Pelosi said at a news conference. “Bring everything to the floor.”

Ryan said Wednesday that an immigration debate would be the GOP’s “next big priority,” but promised a vote only on a bill that Trump would sign. Trump wants cuts in legal immigration in exchange for legal status for the young immigrants, a proposal Democrats dismiss as a nonstarter.

For Ryan, an open immigration debate is anything but easy. Since blocking a major immigration overhaul in 2006 passed by the Senate and backed by GOP President, George W. Bush, Republicans have grown steadily more restrictionist. Trump made an immigration crackdown central to his campaign, riding his promise of a border wall to the presidency.

If Ryan were to allow what conservatives view as amnesty for young immigrants to pass without Trump’s other demands — on mostly Democratic votes and against strong opposition from House Republicans — it could topple him from the speakership.

“There are a large number of Democrats who are going to oppose the bill until there is a commitment by the speaker to have a vote on the Dream Act,” said Rep. Ro Khanna, D-Fremont. Others, he said, are pleased by the increases in spending on domestic programs that have been squeezed for years.

Ryan spokeswoman AshLee Strong sent a note to reporters late Thursday saying if House Democrats oppose the bill, they would be responsible for causing another shutdown.

She argued that because the bill is the product of a bipartisan Senate agreement, “both sides need to deliver votes.” If Democrats fail to do so, she said. “House Democrats will realize how horrible of a position they will be in forcing a government shutdown without the support of Sen. Schumer. It’d be a lonely road.”

Both California senators, Dianne Feinstein and Kamala Harris, voted no on the spending bill. Harris said it was because it failed to provide “a clear pathway” to legal status for the young immigrants. Harris was forced to cancel her keynote address Friday morning at the 2018 State of the Valley Conference in San Jose.

The Senate is expected to open a rare freewheeling debate next week on immigration, following through on a promise McConnell made to Democrats to end last month’s weekend government shutdown. McConnell said Wednesday the debate would begin with no underlying bill and alternate between proposals by both parties.

Carolyn Lochhead is The San Francisco Chronicle’s Washington correspondent. Email: clochhead@sfchronicle.com Twitter: @CarolynLochhead