WASHINGTON — President Donald Trump said Thursday that he wants far-right legislators voted out next year because their defiance could “hurt the entire Republican agenda,” appearing to split with House Speaker Paul Ryan on where to court support for future legislative pushes.

The president tweeted his warning as Ryan (R-Wis.) met with right-leaning policy groups to tout his dedication to “the principles of conservatism.”

Ryan said in a television interview that Trump working with Democrats — as the president has proposed, albeit reluctantly — is “hardly a conservative thing.”

Thursday morning, Trump posted, “The Freedom Caucus will hurt the entire Republican agenda if they don’t get on the team, & fast. We must fight them, & Dems, in 2018!”

In the evening, he singled out conservatives by name for resisting the House GOP health care bill that he and Ryan endorsed.

“Where are @RepMarkMeadows, @Jim_Jordan and @Raul_Labrador? #RepealANDReplace #Obamacare,” the president tweeted.

advertisement | advertise on newsday

House Freedom Caucus members opposed the bill, in part, because they said it was still too intrusive into the free market. Lacking sufficient votes, GOP leaders withdrew the bill last Friday, before a planned House floor vote.

The defeat dealt a blow to Trump’s legislative agenda and his vaunted reputation as a dealmaker.

Since then, Trump has signaled a willingness to strike deals with Democrats going forward, saying they should come to him and cooperate after, he predicted, Obamacare “explodes.”

White House press secretary Sean Spicer said Tuesday: “He’s going to get the votes from wherever he can.”

But Ryan, appearing on “CBS This Morning,” said he worried Republican infighting would “push” Trump to look across the aisle.

The president will “just go work with Democrats to try and change Obamacare and that’s not, that’s hardly a conservative thing,” the speaker said.

Ryan expressed solidarity with influential groups such as Americans for Tax Reform, saying they shared free-market and anti-abortion values.

“We had a setback last week, but we’re not going to let that get us down,” he said, adding they must “seize this historic opportunity we have in front of us to . . . advance these conservative principles.”

advertisement | advertise on newsday

Kyle Kondik, managing editor of Larry Sabato’s Crystal Ball elections newsletter by the University of Virginia’s Center for Politics, said the Freedom Caucus members’ seats are not at risk next year, despite Trump suggesting they would pay at the polls.

“House members hardly ever lose primaries,” Kondik said, adding that although there isn’t a definitive list of Freedom Caucus members, the identifiable ones “represent blood-red Republican districts.”

One Freedom Caucus member, Rep. Justin Amash (R-Mich.), appeared to resent Trump’s tweet and told reporters: “Most people don’t take well to being bullied. . . . It may allow a child to get his way, but that’s not how our government works.”

Rep. Raúl Labrador (R-Idaho) tweeted — more diplomatically — to Trump: “Freedom Caucus stood with u when others ran. Remember who your real friends are. We’re trying to help u succeed.”

Caucus chairman Mark Meadows (R-N.C.) told the Washington Examiner he faulted Trump’s advisers for leading the president to wrongly assign culpability. “I just say he’s not being well-served,” Meadows said.

advertisement | advertise on newsday

Spicer said Trump enjoys support from some in the caucus but doesn’t need their votes “mathematically” to meet his goals.

“He is looking for members on both sides of the aisle who want to be constructive,” Spicer said of health care.