Recipients of the Deferred Action for Childhood Arrivals program listened to Representative Nancy Pelosi, the Democratic minority leader, speak at a news conference last month. Shawn Thew/European Pressphoto Agency

WHITE SULPHUR SPRINGS, W.Va. — President Trump turned up the pressure on Democrats on Thursday to come to an agreement with Republicans on protections for young undocumented immigrants, asserting that opposition leaders “talk a good game” but cared more about politics than actually resolving the matter.

In a speech to Republican lawmakers at their annual retreat, Mr. Trump complained that Democrats were unwilling to budge and would rather see him fail than make progress on immigration or other issues that would benefit the country. At the same time, he warned his fellow Republicans that they would have to make compromises themselves to reach a deal.

“They talk a good game with DACA, but they don’t produce,” Mr. Trump said of Democrats, referring to the Obama-era policy known as Deferred Action for Childhood Arrivals, or DACA, that he has ordered canceled. “Either they come on board or we’re just going to have to really work” to elect more Republicans in the midterm congressional elections in the fall.

Mr. Trump moved in September to end the DACA program, which grants work permits to immigrants brought to the country illegally as children and protects them from deportation, on the grounds that President Barack Obama exceeded his authority by creating it through executive action. But Mr. Trump has expressed support for protecting those immigrants, known as Dreamers, through legislation if Congress can agree. He gave lawmakers until March 5 to take action, though his cancellation of the program is now tied up in the court system.

The president’s comments on Thursday in his speech at the retreat, held at the Greenbrier resort in West Virginia, came hours after he denounced Democrats on Twitter for “doing nothing about DACA.”

Mr. Trump proposed legislation last week that would create a path to citizenship for as many as 1.8 million young undocumented immigrants in exchange for building an expensive border wall, pulling back on family-based immigration and ending a visa lottery program intended to promote diversity among immigrants admitted to the United States.

The president rejected a bipartisan immigration proposal put together by a group of senators last month, and the standoff over immigration helped lead to a three-day government shutdown. Mr. Trump’s State of the Union address, in which he spoke of undocumented immigrants being gang members and killers, did not signal he was amenable to a bipartisan deal he has said he wants. Instead, appropriating a term used to describe the younger immigrants, he said, “Americans are dreamers, too,” a line that angered Democrats.

Trump as Optimist, Salesman or Bully: Mixing Messages in His First Year

In Twitter posts, speeches and interviews, President Trump has expressed variety in his tone and viewpoint, sometimes on the same issue.

Mr. Trump expanded on that on Thursday at the Republican retreat, rejecting the term. “Some people call it Dreamers,” he said. “It’s not Dreamers. Don’t fall into that trap.”

The president expressed pique at Democrats for not applauding during his State of the Union address, even when he hailed record-low unemployment rates among black and Hispanic people.

“When I made that statement the other night, there was zero movement from the Democrats,” he said. “They sat there stone cold, no smile, no applause. You would have thought that on that one they would have sort of at least clapped a little bit. Which tells you perhaps they’d rather see us not do well than see our country do great.”

Democrats resent his claiming credit for falling unemployment among African-Americans not just because he has engaged in racially provocative feuds and equivocated over a white supremacist rally but because the fall in joblessness among blacks began six years before he took office.

Mr. Trump also assailed Representative Nancy Pelosi of California, the Democratic leader, for minimizing the bonuses that some companies are paying workers, citing Mr. Trump’s tax cuts. Ms. Pelosi has said workers were getting “crumbs” compared with what corporations were receiving from the tax cuts and Mr. Trump compared it with Hillary Clinton’s use of the word “deplorables” to describe many of his supporters in 2016.

“She called it crumbs when people are getting $2,000 and $3,000 and $1,000,” Mr. Trump said. “That’s not crumbs. That’s a lot of money.”

Ms. Pelosi’s office responded by saying that Republicans were taking her words out of context to cover up the fact that their tax law enriches their wealthy donors at the expense of working people. “What’s deplorable is Republicans’ desperate effort to hide the multibillion-dollar corporate windfalls of the G.O.P. tax scam behind a handful of meager, one-time bonuses,” said Drew Hammill, her spokesman.

As he addressed the Republican retreat, Mr. Trump took time to affirm that the past year had been filled with successes. He noted that months ago, critics were complaining that he had not kept his promises.

President Trump spoke at the Greenbrier resort in West Virginia where Republican lawmakers are gathered for their annual retreat. Tom Brenner/The New York Times

“Now we’ve fulfilled far more promises than we promised,” he said, adding, “I call it ‘promises plus.’”

In his remarks here, Mr. Trump reprised many of the elements of his State of the Union speech but put a particular focus on immigration, seeming intent on pressuring Republicans as well as Democrats to come to the table.

“We’re going to have to compromise unless we elect more Republicans, in which case we can have it just the way everybody in this room wants it,” he said. “We have to be willing to give a little in order for our country to gain a whole lot.”

Speaking to reporters earlier in the day, Senator John Thune of South Dakota, the No. 3 Senate Republican, suggested that the best approach might be to narrow the scope of the legislation to only two of the four “pillars” that the president has proposed addressing, leaving out family-based immigration and the diversity visa lottery.

“I think that if we can solve DACA and border security, that may be the best we can hope for,” he said. He described such a plan as a “fallback position that can pass the House, the Senate and get signed,” adding that if “other issues enter into that conversation, it gets more complicated.”

With Republicans gathered for their retreat, their internal divisions over immigration were plainly visible, and the road ahead was far from clear. A schedule for the retreat listed no sessions on the subject.

“I’m not interested in a skinny version on immigration,” Senator James Lankford, Republican of Oklahoma, said hours after Mr. Thune offered his suggestion.

Representative Mark Meadows, Republican of North Carolina and the chairman of the conservative House Freedom Caucus, quickly dismissed Mr. Thune’s idea of a narrowed bill as well.

“Senator Thune represents a state that’s a long ways from the southern border,” he said. “Making a suggestion that a two-pillar answer is going to get support in the House is a nonstarter.”