WASHINGTON — President Donald Trump said on Wednesday that he is open to a path to citizenship after 10 to 12 years for hundreds of thousands of immigrants brought illegally to the United States as children, days after rejecting a bipartisan plan with that as its centerpiece.

Trump once again seemed to undercut his administration's message, telling reporters at the White House that he would allow the young immigrants, known as Dreamers, to "morph into" citizens over a period of time.

The reporters had gathered for a briefing from a senior official detailing the administration's plans to stick to a restrictive immigration agenda when the president dropped in unprompted, shortly before departing for Davos, Switzerland, pre-empting the official.

"Over a period of 10 to 12 years," Trump said, "somebody does a great job, they work hard — that gives incentive to do a great job. Whatever they're doing, if they do a great job, I think it's a nice thing to have the incentive of, after a period of years, being able to become a citizen."

In September, Trump ended an Obama-era program, called Deferred Action for Childhood Arrivals, or DACA, saying it was an illegal assertion of executive authority by his predecessor. But even as Trump's actions threatened nearly 700,000 young immigrants with deportation when the program expires March 5, he has urged Congress to find a permanent solution that could allow them to live and work in the country legally.

The fate of the Dreamers is at the center of a furious stalemate in Congress, where Republicans and Democrats are struggling to find a compromise. Trump's positions have been difficult to discern, vacillating between his expressions of sympathy for the DACA recipients and his hard-line demands for a crackdown on unauthorized immigrants.

Trump campaigned for the presidency with nativist rhetoric that assailed the threat from outsiders, especially Mexicans and Muslims. As president, he quickly tried to impose a travel ban on predominantly Muslim countries and gave immigration agents more authority to round up unauthorized immigrants.

But he also once said that he wanted "a bill of love" to address the fate of the DACA recipients.

Sen. Tom Cotton, R-Ark., who is a hard-line conservative on immigration issues, reiterated that any deal on immigration would have to include Republican demands for tougher enforcement on immigration, saying on Twitter that "it must be done responsibly, guaranteeing a secure & lawful border & ending chain migration, to mitigate the negative side effects of codifying DACA."

Trump's remarks drew support from Sen. Lindsey Graham, R-S.C., who has in recent weeks been at the forefront of efforts to reach an immigration deal. Graham had been one of the architects of the bipartisan plan rejected by Trump.

"President Trump's support for a pathway to citizenship will help us get strong border security measures as we work to modernize a broken immigration system," Graham said in a statement. "Finally with this statement we are on track to solving the immigration problem which is the political key to rebuilding our military."

Sen. Richard J. Durbin, D-Ill., who has been leading the bipartisan talks with Graham, also praised the president. "The President is headed in the right direction here," Durbin wrote on Twitter.

As the Trump administration struggled in recent days to produce an on-message stance on immigration, the publicity-loving Trump has kept largely out of sight, particularly as lawmakers in both parties worked to reopen the government after a three-day shutdown. Earlier on Wednesday, Sarah Huckabee Sanders, the White House press secretary, said administration officials would release a "legislative framework" on Monday that will be designed to emphasize conservative demands for tougher immigration enforcement and border protection.

Within hours, Trump's off-the-cuff comments to reporters seemed, again, to suggest flexibility. But his remarks sent the White House staff scrambling in what one official called a "fire drill." After delaying the briefing for nearly an hour, Trump's aides decided to postpone it until Thursday as they tried to reconcile their plans with the president's words.

In addition to suggesting a pathway to citizenship for the Dreamers, Trump said that he will request $25 billion to build a wall along the United States border with Mexico, though he said he would build it "way under budget." He also said that his plan would include a request for $5 billion for additional security measures along the border.

Trump, once again, said he will insist on an end to the diversity lottery system, which encourages immigration from a variety of countries. Trump referred to the program as a "broken system" that brings the wrong kind of people into the United States. He said that he wanted to negotiate an end to chain migration, but said he would work to allow nuclear families to stay together.

The president's reassurance to one population stood in contrast with actions taken earlier Wednesday by his Justice Department, which asked 23 jurisdictions across the country to furnish documents proving that they had not kept information from federal immigration authorities. The Justice Department's move caused several Democratic mayors from some of the country's largest cities to boycott a White House meeting with Trump.

"Protecting criminal aliens from federal immigration authorities defies common sense and undermines the rule of law," Attorney General Jeff Sessions said in a statement. "Enough is enough."

The protest against the letter and Sessions' comments added a local dimension to the roiling national debate. Mitch Landrieu, the mayor of New Orleans and the president of the U.S. Conference of Mayors, said on Wednesday at a news conference in Washington that he saw the Justice Department's move as an "attack," and that he could not "in good conscience" attend the White House meeting.

Over the past year, sanctuary cities have pushed back hard on the administration's attempts to force them to abandon their stance by cutting off federal funding to them, with some like Chicago filing lawsuits against the Justice Department.

"President Trump shouldn't invite us to the White House for a meeting on infrastructure and three hours before issue the equivalent of what are arrest warrants for standing up for what we believe in and, by the way, what America believes in," said Mayor Rahm Emanuel of Chicago.

Sessions has taken a hard line on the issue since his days as an Alabama senator. Since Trump took office, both men have focused on sanctuary cities, which generally refuse to hold people on immigration agents' behalf without a warrant from a judge, accusing such places of flouting the law and helping convicted criminals evade deportation.

Armed with the news that several Democratic mayors had declined an invitation to the White House, Trump again returned to a partisan stance on immigration.

"The mayors who choose to boycott this event have put the needs of criminal, illegal immigrants over law-abiding America," Trump said at the event, held hours before he dropped in on reporters.

As he ended his conversation with reporters and prepared to leave for the World Economic Forum in Davos, Trump jokingly suggested that he would like a deal on immigration in place by the time he returns.