Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

WASHINGTON — Congress passed a stopgap spending bill on Thursday to prevent a government shutdown this weekend and buy time for challenging talks on a wide range of unfinished business on Capitol Hill.

The measure passed largely along party lines in the House of Representatives, 235-193, but earned greater approval in the Senate, 81-14. The bill, which would keep the government running through Dec. 22, will now be sent to President Donald Trump.

The votes came as Trump and top congressional leaders in both parties huddled to discuss a range of unfinished bipartisan business on Capitol Hill, including the budget, a key children's health program and aid to hurricane-slammed Puerto Rico, Texas and Florida — and, for Democrats and many Republicans, protections for immigrants brought to the country illegally as children.

In back-to-back statements, both sides declared the meeting "productive."

"We had a productive conversation on a wide variety of issues. Nothing specific has been agreed to, but discussions continue," said Capitol Hill's top Democrats, Sen. Chuck Schumer of New York and Rep. Nancy Pelosi of California, ticking off a roster of Democratic priorities, including domestic spending increases, funding for veterans and money to battle opioid abuse, immigration and health care.

GOP leaders promised help for immigrants known as Dreamers by their supporters, many of whom have only known America as their home.

Spokesmen for House Speaker Paul Ryan, R-Wis., and Senate Majority Leader Mitch McConnell, R-Ky., said GOP leaders "stressed the need to address border security, interior enforcement and other parts of our broken immigration system," adding that the tricky immigration issue "should be a separate process and not used to hold hostage funding for our men and women in uniform."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Negotiations are sure to be tricky. Pelosi staked out a hard line Thursday and insisted that any year-end deal solve the immigration issue.

The immigrants are viewed sympathetically by the public and most lawmakers but face deportation in a few months because Trump reversed administrative protections provided to them by former President Barack Obama.

Pelosi told reporters before the meeting that "We will not leave here" without helping the immigrants. Her stance was noteworthy because GOP leaders are likely to require Democratic votes for the pre-Christmas spending bill.

Pelosi returned from the White House to oppose Thursday's stopgap bill. Fourteen Democrats supported the measure, however, while 18 Republicans were opposed.

Among Republicans, the conservative House Freedom Caucus had resisted the pending stopgap measure earlier in the week, fearing it would lead to a bad deal for conservatives down the road. But on Thursday, the group's chairman, Rep. Mark Meadows, R-N.C., said the group will likely give leaders whatever support they need to pass the legislation.

Meadows said they'll help it pass to avoid distractions from the GOP drive to push their treasured $1.5 trillion tax bill through Congress this month. That measure, which mostly benefits businesses and upper-income people, is Trump's and the GOP's top remaining priority and would be their first major legislative triumph of the year.

But hours before Trump was to bargain with congressional leaders at the White House over longer-term spending decisions, Meadows said the conservatives would oppose any agreement they feel allows excessive federal spending.

"I want to avoid a headline that says President Trump's administration just passes the highest spending levels in U.S. history," Meadows told two reporters. "There will be zero support on numbers that are too high, regardless of anybody's position on that."

He also said Ryan promised he'd fight in coming weeks to pass a full-year budget for the military and leave fights with Democrats over domestic spending for later. It is unclear how that strategy would work, since Republicans control the Senate 52-48 and will need at least eight Democratic votes to pass any spending legislation.

The prospects for successful White House talks were buffeted Wednesday when the impulsive Trump blurted to reporters that a shutdown "could happen." He blamed Democrats, saying they want "illegal immigrants pouring into our country, bringing with them crime, tremendous amounts of crime."

Last week, an unexpected attack by Trump on Senate Minority Leader Chuck Schumer, D-N.Y., and Pelosi prompted the two to skip a bargaining session that was planned then.

This time, the White House smoothed the waters by following up with a more peaceable, written statement. It praised Pelosi and Schumer for choosing to "put their responsibility to the American people above partisanship" and said Trump was anticipating productive talks between "leaders who put their differences aside."

The two-week spending bill also makes money available to several states that are running out of funds for the Children's Health Insurance Program. That widely popular program provides medical care to more than 8 million children.

While many Democrats seemed likely to oppose the short-term bill, enough were expected to support it in the Senate to allow its passage there. They know they'd still have leverage on subsequent bills needed to keep the government running.

Democrats promise to use their leverage to insist on spending boosts for health care, infrastructure and other domestic programs that would match increases Republicans want for defense.