President Trump’s effort to strike an immigration deal with Democrats attracted cautious support from lawmakers of both parties Thursday even as it prompted a swift backlash from scattered conservatives and an attempt by irritated Republican leaders to reassert their authority.

House Speaker Paul D. Ryan (R-Wis.) dismissed the potential deal negotiated late Wednesday over dinner at the White House between Trump and Capitol Hill’s top two Democrats as little more than a preliminary discussion — and insisted that any agreement must have buy-in from GOP leaders.

Yet Ryan agreed in broad terms with the president’s goal of protecting hundreds of thousands of undocumented immigrants while postponing talk of a border wall but toughening U.S. border security in other ways.

“If we have the support of President Trump on the kinds of things I just said, getting security and enforcement along with the solution here [for ‘dreamers’], that I believe will get a majority of our members, because our members support President Trump,” he said.

Ryan and his Senate counterpart, Majority Leader Mitch McConnell (R-Ky.), have been in limbo since Trump turned to Democrats last week, brokering a deal to raise the debt ceiling and fund the government — and effectively forcing GOP leaders to the sidelines.

Their uncomfortable position was obvious Thursday, when Ryan confirmed that he didn’t learn of the potential deal with House Minority Leader Nancy Pelosi (D-Calif.) and Senate Minority Leader Charles E. Schumer (D-N.Y.) until Thursday morning, when Trump and White House Chief of Staff John F. Kelly confirmed it in phone conversations from Air Force One more than 12 hours after the dinner meeting.

Ryan stated that any discussion of a “Dream Act” to protect undocumented immigrants brought into the country as children must originate with House Republicans. “There is no agreement,” he said at a news conference on Capitol Hill.

“The president understands he has to work with the congressional majorities to get any kind of legislative solution,” he added.

McConnell remained noncommittal about a possible deal — and put the onus on the White House to come up with a proposal.

“We look forward to receiving the Trump administration’s legislative proposal as we continue our work on these issues,” he said in a statement.

Despite these comments, many rank-and-file Republicans indicated that they are open to whatever the president supports, particularly if it includes stronger border controls and interior enforcement.

“I know there’s a hue and cry from around the country as relates to what happened last night — I’m sorry,” said Sen. Bob Corker (R-Tenn.). “I’ve been here 10 years and eight months now, there’s been way, way too much gridlock here, and if the president can sit down with leaders of the other party and bring consensus on an issue like he did last night, I’m all for it.”

Yet Trump’s unpredictability remained a constant throughout the day, as he repeatedly stated that he wasn’t considering allowing dreamers — undocumented immigrants brought to the United States as children — to become citizens. This stance put him at odds with Schumer and Pelosi, who believed he supported the idea.

“We’re not looking at citizenship,” Trump told reporters on an airport tarmac in Florida, where he toured relief efforts following Hurricane Irma. “We’re not looking at amnesty. We’re looking at allowing people to stay here. . . . We’re talking about taking care of people, people who were brought here, people who’ve done a good job.”

Schumer said that was not his understanding from the White House dinner the previous evening.

“There was no debate about that. We discussed the ramifications of the bill and there was no dissent, no ‘oh, we can’t support this part or that part.’ That hasn’t changed. No one has said that won’t happen,” Schumer said.

A path to citizenship could complicate the debate for many Republicans, said Rep. Mark Meadows (R-N.C.), chairman of the conservative House Freedom Caucus. But most GOP members seemed to adopt a wait-and-see attitude as the White House hammered out its plan.

Some Democrats expressed concern about trusting Trump. Rep. Jim McGovern (D-Mass.) spoke for many Democrats when he urged leaders to proceed with caution.

“I’ve no idea how Donald Trump’s brain works. All I know is, he’s caused a lot of concern and anxiety among 800,000 people, and we’ve got to find a way to fix this,” McGovern said. “I know where his heart is, and it’s not where mine is. So we’re all a little bit skeptical because of who he is. When it comes to immigrants, he’s not a very nice person.”

Schumer and Pelosi, however, appeared encouraged by their new position of influence at a time when Republicans control the White House and both houses of Congress.

On Thursday morning, an energetic Schumer was caught on a hot mic on the Senate floor reflecting on the previous night’s dinner.

“He likes us,” Schumer appeared to say about the president. “He likes me, anyway. . . . Here’s what I told him: ‘Mr. President, you’re much better off if you do one step right, and one step left. If you just step in one direction, you’re boxed.’ He gets that.”

Schumer said that Democrats should trust that in this case Trump is negotiating in good faith.

“He said he would do this and I take him at his word that he will,” the senator said, adding later: “We thought we had an opportunity to get something good and let’s see what happens. We’re very hopeful that they will keep their word.”

Specific talks on border security are expected to begin in the coming days, Schumer said. He and Pelosi said border security measures in the final agreement could include drones, sensor technology, road repairs and other strategies that were included in a bipartisan bill in 2013 that instructed federal officials to draft a plan ensuring apprehension of 90 percent of all illegal border-crossers within five years.

Some Republicans want tougher immigration enforcement and mandatory use of the E-Verify employment eligibility system as part of a final deal.

But even immigration hard-liners such as Rep. Lou Barletta (R-Pa.) seemed open to hearing what the White House comes up with.

“We want to have compassion for these children. At the same time, the American people need to be brought into this too. What will they get?” Barletta asked.

He said he’s not disappointed in Trump. “He’s kept his promises on the campaign trail. I have no reason to believe he’s not going to,” Barletta said.

Hard-line conservatives had initially reacted to Trump’s agreement with shock and outrage.

Rep. Steve King (R-Iowa) tweeted Wednesday night that the deal would ensure that Trump’s base is “blown up, destroyed, irreparable, and disillusioned beyond repair.”

King elaborated Thursday. “He hasn’t had enough voices reminding him of his campaign promises, and I want to remind him,” King said, acknowledging that “it’s harder to resist the president of your own party.”

Trump said Thursday that he would agree to a deal only if it includes “extreme security.”

“We want to get massive border security. And I think that both Nancy Pelosi and Chuck Schumer, I think they agree with it,” Trump said on the Florida tarmac. “Look, 92 percent of the people agree on DACA, but what we want is very, very powerful border security, okay?”

No matter where the negotiations go in the coming weeks, they will not include serious consideration of a GOP plan to limit legal immigration.

The Raise Act, proposed by Sens. Tom Cotton (R-Ark.) and David Perdue (R-Ga.), would halve legal immigration levels over the next decade and cap annual refu­gee admissions at 50,000.

While the bill is popular with Trump’s most ardent supporters and conservative lawmakers, it is widely opposed by Democrats and many Republicans, who see it as potentially harmful to the economy and a break with decades of American tradition.

Trump supports the measure, but he agreed Wednesday not to include it as part of any Dream Act agreement, according to multiple people familiar with the meeting who asked for anonymity to speak candidly about it.

Regardless, the path ahead could be perilous for Democrats.

Rep. Raúl Grijalva, vice chairman of the Congressional Hispanic Caucus, said he worries that the White House is sending mixed messages about Trump’s true intentions on immigration. The discussion of border security appears to be drifting away, Grijalva said, from investing in new border-monitoring technology and toward more aggressive enforcement tactics.

The Arizona Democrat said many members are worried that pairing border security with protections for immigrants in a single bill could put Democrats in the difficult position of deciding whether to vote for a Dream Act that includes security measures they oppose.

“I really believe that every one of us is going to face a crucible where there is going to be something in the security package that we have opposed,” Grijalva said.

In the House, these concerns led members of the minority to discuss working with GOP leaders to allow separate votes on proposals to protect young immigrants and bolster border security.

But those familiar with the idea, who asked for anonymity to speak frankly about the talks, stressed that it is in the preliminary stages and may ultimately not be feasible.

Paul Kane, Kelsey Snell and Amber Phillips contributed to this report.