WASHINGTON — President Trump on Tuesday appeared open to negotiating a sweeping immigration deal that would eventually grant millions of undocumented 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 undocumented immigrants brought to the United States as children. The 90-minute session — more than half of which played out on national television — appeared to produce some progress: Mr. Trump agreed to a framework for a short-term immigration deal to couple protection for young, undocumented immigrants with border security.

But in suggesting that a broader immigration measure was possible next, Mr. 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 undocumented immigrants already living and working in the United States. Passage of a comprehensive immigration law would give Mr. 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.