“Certain Washington politicians choose to fight for foreign countries, but President Trump will always fight for the American people,” Mr. Shah said. “Like other nations that have merit-based immigration, President Trump is fighting for permanent solutions that make our country stronger by welcoming those who can contribute to our society, grow our economy and assimilate into our great nation.”
But the president’s vulgar language on a delicate issue left the fate of the broader immigration debate in limbo and had the potential to torpedo the chances of achieving the deal being sought to protect about 800,000 undocumented immigrants brought to the country as children. And they drew a backlash from Republican and Democratic lawmakers, many of whom called Mr. Trump’s utterances unacceptable at best and plainly racist at worst.
Representative Mia Love, a Republican of Utah who is of Haitian descent, demanded an apology from the president, saying his comments were “unkind, divisive, elitist, and fly in the face of our nation’s values.”
“This behavior is unacceptable from the leader of our nation,” Ms. Love went on in an emotional statement that noted her heritage and that her parents “never took a thing” from the government while achieving the American dream. “The president must apologize to both the American people and the nations he so wantonly maligned.”
“As an American, I am ashamed of the president,” said Representative Luis V. Gutiérrez, Democrat of Illinois. “His comments are disappointing, unbelievable, but not surprising. We always knew that President Trump doesn’t like people from certain countries or people or certain colors.” He added, we can now “say with 100 percent confidence that the president is a racist who does not share the values enshrined in our Constitution or Declaration of Independence.”
The reactions were extraordinary bipartisan rebukes to a sitting president, but they only fanned what has been a long-simmering debate over Mr. Trump’s views and talk on race.
As a candidate, Mr. Trump, who rose to political prominence questioning the validity of President Barack Obama’s birth certificate, branded Mexican immigrants rapists and criminals, called for a ban on Muslims entering the United States and was slow to disavow the support of the former Ku Klux Klan leader David Duke.
As the president, Mr. Trump has ordered a broad immigration crackdown while privately railing against immigrants from predominantly black countries and has repeatedly stoked racial divisions, denouncing “both sides” for violence after a white supremacist rally in Charlottesville, Va., and singling out black athletes for failing to stand for the national anthem before their games.
The episode at the White House, first reported by The Washington Post, unfolded as Mr. Trump was hosting a meeting with Senator Lindsey Graham, Republican of South Carolina, and Richard J. Durbin, Democrat of Illinois, who are working to codify the protections in the Deferred Action for Childhood Arrivals program, or DACA, the Obama-era initiative that provided temporary work permits and reprieves from deportation to immigrants brought to the United States as children by their parents.
Also present were Representative Kevin McCarthy, Republican of California and the majority leader; Senator David Perdue, Republican of Georgia; Senator Tom Cotton, Republican of Arkansas; and Representative Robert W. Goodlatte, Republican of Virginia and the chairman of the Judiciary Committee.
None of the lawmakers would comment on Mr. Trump’s remarks.
The plan outlined by Mr. Graham and Mr. Durbin, according to people familiar with it, would also include more than $2.5 billion for border security and a grant of protected status for the parents of the immigrants, known as Dreamers, who would be barred from sponsoring their parents for citizenship.
Mr. Trump grew angry as the group detailed another aspect of the deal — a move to end the diversity visa lottery program and use some of the 50,000 visas that are annually distributed as part of the program to protect vulnerable populations who have been living in the United States under what is known as Temporary Protected Status. That was when Mr. Durbin mentioned Haiti, prompting the president’s criticism.
When the discussion turned to African nations, the people with knowledge of the conversation added, Mr. Trump asked why he would want “all these people from shithole countries,” adding that the United States should admit more people from places like Norway.
About 83 percent of Norway’s population is ethnic Norwegian, according to a 2017 C.I.A. fact book, making the country overwhelmingly white.
Mr. Trump has long argued that the United States should base legal immigration on merit and skills rather than family ties, seeking new entrants who are highly educated, capable of assimilating and unlikely to use government programs for the poor. Some people familiar with his comments argued privately on Thursday night that the president had only tried to press that point, using salty language.
But it was the language he used that shocked and appalled many lawmakers and created a public outcry — the vulgar phrase Mr. Trump uttered quickly began trending on Twitter — overshadowing the substance of the DACA talks, and with it, the future of the immigrants at risk of deportation should those discussions fail.
Representative Cedric L. Richmond, Democrat of Louisiana and the chairman of the Congressional Black Caucus, called the president’s closed-door comments “yet another confirmation of his racially insensitive and ignorant views” and said they reinforced “the concerns that we hear every day, that the president’s slogan, ‘Make America Great Again,’ is really code for ‘Make America White Again.’”
Senator Richard Blumenthal, Democrat of Connecticut, described the comments as “the most odious and insidious racism masquerading poorly as immigration policy,” and argued that they would make it more difficult for the two parties to reach consensus on an immigration deal.
“It inflames and encourages the worst instinct and the basest dark side of immigration issues,” Mr. Blumenthal said. He added that he had spoken with several Senate colleagues who expressed “a combination of disbelief and a sense of repugnance” at what the president had said.
Mr. Durbin spoke with reporters briefly after the White House gathering, but did not share what the president had said. Looking dejected, he said he and Mr. Graham had gone to meet with Mr. Trump hoping to get the president’s blessing for their bipartisan plan.
“The president is not prepared to do that at this moment,” Mr. Durbin said, adding, “I don’t know what happens next.”
The meeting had gotten off to a grim start after Mr. Durbin and Mr. Graham, who had been summoned by Mr. Trump to discuss their compromise proposal, arrived to find a gaggle of Republicans they had not expected, including immigration hard-liners who have been skeptical of a DACA deal, filing into the room to discuss the plan.
One of them, Senator Tom Cotton, Republican of Arkansas, later offered a blistering appraisal of the Durbin-Graham deal, calling it “a joke of a proposal” and arguing that Democrats had not offered Republicans “anything legitimate in return” for accepting legal status for the Dreamers.
The White House session was the second time this week that Mr. Trump has met with members of Congress to address the fate of the Dreamers, whose protections under DACA are set to expire in March after Mr. Trump moved to rescind the policy in the fall.
On Tuesday, Mr. Trump convened a televised bipartisan negotiating session on the issue in which he said he wanted lawmakers to negotiate a “bill of love” for the DACA recipients and tasked the Democratic and Republican leaders in both the House and the Senate to negotiate a final deal.
Senator John Cornyn, Republican of Texas and the No. 2 Senate Republican, said Thursday that any immigration compromise could not simply be hammered out by a small group of senators, referring to Mr. Durbin and Mr. Graham.
“I think what the president told them is it’s fine for them to have negotiated what they think is a reasonable proposal, but what they need to do is share that with others so that it will have broad enough support to actually get passed,” Mr. Cornyn said, adding, “We need to have more than six votes for a proposal.”
When he first moved to rescind the DACA program, Mr. Trump gave lawmakers six months to come up with a replacement. But Democrats have pressed to include a solution in a broad spending package, which must be completed by a deadline of next Friday, when a short-term bill funding the government will expire. They are under extraordinary pressure from their progressive base to withhold their votes to keep the government open unless the immigration measure is included.
One of the Senate negotiators, Jeff Flake, Republican of Arizona, cast doubt on passing a bill by that deadline. But he expressed hope that the deal being put together by Mr. Durbin’s group could move ahead soon.
“It’s the only game in town,” Mr. Flake said. “There’s no other bill.”
A previous version of this article included an incorrect figure for the spending proposed on border security under a bipartisan immigration deal. The proposal includes $2.7 billion in border security spending, not $2.7 million.