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.