by Julie Hirschfeld Davis and Sheryl Gay Stolberg

WASHINGTON — President Donald Trump on Tuesday appeared open to negotiating a sweeping immigration deal that would eventually grant millions of unauthorised immigrants a pathway to citizenship, declaring that he was willing to “take the heat” politically for an approach that seemed to flatly contradict the anti-immigration stance that charged his political rise.

The president made the remarks during an extended meeting with congressional Republicans and Democrats who are weighing a shorter-term agreement that would extend legal status for immigrants brought to the United States illegally as children. The 90-minute session — more than half of which played out on national television — appeared to produce some progress: Trump agreed to a framework for a short-term immigration deal to couple protection for young, unauthorised immigrants with border security.

But in suggesting that a broader immigration measure was possible next, Trump was giving a rare public glimpse of an impulse he has expressed privately to advisers and lawmakers — the desire to preside over a more far-reaching solution to the status of the 11 million unauthorised immigrants already living and working in the United States. Passage of a comprehensive immigration law would give Trump success where Presidents Barack Obama and George W. Bush, failed.

The push for an immigration deal with Democrats has the potential to alienate the hard-line anti-immigration activists who powered his political rise and helped him win the presidency, many of whom have described it as amnesty for lawbreakers. If he succeeds, it could be compared to Richard Nixon’s historic trip to China. Only an anti-communist hard-liner could have made the opening acceptable to his supporters.

If he fails, it would be more like Ronald Reagan in Reykjavik, Iceland, where he suggested eliminating much of the U.S. and Soviet nuclear arsenal, a glimmer of idealism that was crushed by a backlash from his own party.

Sen. Lindsey Graham, R-S.C., floated the idea of a broader immigration deal during the meeting in the White House Cabinet Room on Tuesday, making clear that it would have to include a pathway to citizenship for unauthorised immigrants already in the country.

Trump replied: “If you want to take it that further step, I’ll take the heat. I will take all the heat. You are not that far away from comprehensive immigration reform.”

Lawmakers from both parties were taken aback by the president’s words.

“My head is spinning with all the things that were said by the president and others in that room in the course of an hour and a half,” said Sen. Richard J. Durbin, D-Ill., who has been leading the talks.

The president has been known to make conflicting or contradictory statements on complex policy issues, only to walk them back or change his mind. White House officials declined to provide specifics about what kind of immigration overhaul the president would favour, saying he was focused on the shorter-term measure that would shield unauthorised immigrants brought to the country as children from deportation, in exchange for more border agents and a down payment on a border wall.

Hours after the meeting, Trump appeared to harden his insistence on the wall, writing on Twitter, “As I made very clear today, our country needs the security of the Wall on the Southern Border, which must be part of any DACA approval.”

And later Tuesday, a federal judge in San Francisco ordered the Trump administration to reverse its move to end protections for unauthorised immigrants brought to the country illegally as children, throwing the legal status of enrolees further into doubt and potentially complicating the politics of a legislative deal to permanently address their situation.

But the comments earlier Tuesday were a remarkable break with the divisive messaging that propelled Trump to the White House and the harsh policies that have defined his first year in office, marked by efforts to demonise and deport immigrants who have entered the country illegally.

The administration has also moved to curtail legal channels for immigration like refugee resettlement and temporary protections for vulnerable groups, including Salvadorans who have been allowed to live and work legally in the United States after earthquakes struck their country in 2001.

Instead, the president presented himself on Tuesday as a dealmaker eager to find common ground and unconcerned with — if not unaware of — the political perils of immigration debates. The phrase “comprehensive immigration reform” is detested by anti-immigration activists.

“I don’t think it’s going to be that complicated,” Trump told lawmakers assembled around his Cabinet table of a broad immigration measure.

Republican senators were deeply skeptical.

“I don’t think comprehensive reform is as imminent as he would think it could be,” Sen. Charles E. Grassley of Iowa said after returning from the White House.

Trump’s call for a comprehensive solution came just after Graham had said he was a proponent of “a pathway to citizenship for 11 million people,” and then predicted “a drumbeat” of vitriol against such an approach. “Right-wing radio and talk show hosts are going to beat the crap out of us,” he said. “It’s going to be ‘amnesty’ all over again.”

Trump almost seemed to relish such a fight.

“My whole life has been heat,” he shrugged. “I like heat, in a certain way.”

The White House meeting itself was extraordinary, an extended negotiating session that was broadcast by the news channels at a time when questions about Trump’s mental acuity and fitness for his job have been dominating the headlines.

The president appeared to signal a willingness to compromise with Democrats on the border security provisions that he says must be part of a near-term agreement to codify the protections created under DACA, or Deferred Action for Childhood Arrivals, the Obama-era program that he has moved to end by March that shields from deportation those brought to the United States illegally as children.

He called it a “bill of love,” echoing the language of Jeb Bush, one of his rivals for the Republican nomination in 2016 whom he once ridiculed. On Tuesday, Bush praised the president for seeking a bipartisan solution, while immigration hard-liners ridiculed Trump for sounding like the former Florida governor.

“Donald J. Trump,” read one slogan circulated by an anti-immigration expert, Mark Krikorian, showing a scene from Tuesday’s meeting. “(The “J” is for ¡Jeb!)”

Nearly 800,000 young immigrants were shielded from deportation under the DACA program, which granted them renewable two-year work permits. Immigrant rights advocates say 14,000 of the young people have already lost their protected status because their permits have expired, and they have been unable to renew them.

Lawmakers returning from the White House meeting said Democrats and Republicans had agreed on four topics to be negotiated as part of a narrower DACA deal: the fate of beneficiaries of the program, border security, family-based immigration and the visa lottery. A few Democrats and Republicans have been meeting for months to try to hammer out a deal along those lines, and the president’s backing of that scope was a startling shift for them.

“It was a better meeting than I expected," said Sen. Jeff Flake, R-Ariz., who has participated in those talks. “You can’t negotiate that much with that many people but the president expressed flexibility.”

Still, Congress has a lot of work ahead on these areas before lawmakers come to a deal that everyone can agree on.

During the session, Trump repeatedly returned to his call for a broad and comprehensive immigration bill, even as Democratic and Republican lawmakers cautioned him of the failures of the past. Some Republicans said Trump was being too ambitious. Even Democrats worried that more immediate immigration matters might fail to pass with the broader package now on the table.

“The fierce urgency of now is for these 800,000 Dreamers,” said Sen. Robert Menendez, D-N.J., referring to the nickname for the young immigrants now in limbo.

Democrats have insisted that protections for those immigrants be part of any agreement to fund the government beyond Jan. 19, when current funding expires.

But the president said action on the more ambitious immigration measure would be possible as soon as the next day.

“We can do DACA and start comprehensive reform the following afternoon,” Trump said.

Previous attempts to enact such a broad bipartisan immigration compromise, during the Bush and Obama presidencies proved politically impossible. After months of arduous negotiations, comprehensive immigration bills passed the Senate in 2006 and in 2013 only to be stymied in the House.

“You created an opportunity here, Mr. President,” Graham said to Trump, “and you need to close the deal.”

The president’s pivot drew swift rebukes from conservatives and immigration activists who have been among Trump’s staunchest supporters.

Roy Beck, the executive director of NumbersUSA, which pushes for reducing immigration, said the deal Trump envisioned, like previous grants of amnesty, would bolster both illegal and legal immigration levels, flooding the U.S. labor market.

“Amnesty-now and enforcement/reform-later agreements always fail the American people,” Beck said in a statement. “President Trump must hold fast to his compact with American workers to greatly reduce both the illegal and legal competition from mass migration.”

The president said he would insist on strict new immigration limits as part of any such measure, although he seemed to concede that his call for a “wall” might not entail the kind of physical barriers that many Democrats have viewed as a nonstarter.

He conceded that, “We don’t need a 2,000-mile wall,” because parts of the border are impassible, and noted that Democrats had voted for border fencing in the past. Afterward, Republicans and Democrats both said they believed Trump was using the term “wall” to describe border security, not necessarily a giant physical barrier.