President Donald Trump warned the House Freedom Caucus on Thursday that he would work to unseat them in the 2018 midterm elections if they did not cooperate with the broader Republican agenda.

The Freedom Caucus’ objections to the GOP Obamacare replacement bill, known as the American Health Care Act, proved decisive in killing it last Friday. The legislative defeat was a major humiliation for Trump and House Speaker Paul Ryan (R-Wis.) who had repeatedly promised to repeal and replace Obamacare, officially known as the Affordable Care Act.

Trump threatened the roughly 32-member group of ultraconservative Republicans with electoral reprisal on Twitter “if they don’t get on the team, & fast.”

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! — Donald J. Trump (@realDonaldTrump) March 30, 2017

Rep. Justin Amash (R-Mich.), one of the Freedom Caucus’ staunchest members, responded defiantly to Trump, tweeting that it “didn’t take long for the swamp to drain” Trump.

It didn't take long for the swamp to drain @realDonaldTrump. No shame, Mr. President. Almost everyone succumbs to the D.C. Establishment. https://t.co/9bDo8yzH7I — Justin Amash (@justinamash) March 30, 2017

With the Republicans’ Obamacare replacement bill on life support last Friday morning, Trump tried to shame the Freedom Caucus on Twitter into getting on board with it by appealing to their anti-abortion views. The group of lawmakers, Trump alleged, would “allow [Planned Parenthood] to continue if they stop this plan!”

The irony is that the Freedom Caucus, which is very pro-life and against Planned Parenthood, allows P.P. to continue if they stop this plan! — Donald J. Trump (@realDonaldTrump) March 24, 2017

After Trump and Ryan decided to pull the bill on Friday afternoon, the president continued to lambaste the Freedom Caucus for undermining the Republican agenda.

Democrats are smiling in D.C. that the Freedom Caucus, with the help of Club For Growth and Heritage, have saved Planned Parenthood & Ocare! — Donald J. Trump (@realDonaldTrump) March 26, 2017

The Republican House Freedom Caucus was able to snatch defeat from the jaws of victory. After so many bad years they were ready for a win! — Donald J. Trump (@realDonaldTrump) March 28, 2017

The House Freedom Caucus is not the only faction of the Republican Party responsible for sinking the GOP health care proposal. The last-minute exodus of moderate Republicans sealed its fate.

Republican leaders’ attempts to assuage the Freedom Caucus by letting states regulate which “essential benefits” insurance exchange plans had to cover contributed to these defections and likely doomed the bill in the Senate.

The president has also pointed his finger at others. He first attributed the loss to Democrats’ unwillingness to cooperate, despite never reaching out to them.

On Saturday, Trump also directed his Twitter followers to tune into a Fox News segment in which his friend Judge Jeanine Pirro faulted Ryan for the bill’s demise and called for his resignation.

Bill Pugliano/Getty Images President Donald Trump is upset that members of the ultraconservative House Freedom Caucus objected to the GOP's Obamacare replacement bill. Their opposition helped kill it.

For their part, Freedom Caucus members claim that Trump’s lack of interest in the policy details of the bill prevented him from accommodating their demands.

If Trump in fact plans to proceed with a plan to dislodge the notoriously independent members of the House Freedom Caucus in primary elections, he has his work cut out for him. The members are almost entirely clustered in extremely conservative congressional districts where their ideology-driven stubbornness is a political asset.

Asked on Thursday afternoon whether Trump appreciated the significance of starting a fight with one of Congress’s most cohesive voting blocs, White House press secretary Sean Spicer suggested Trump was seeking ways to circumvent the Freedom Caucus or dilute its power. Some individual Freedom Caucus members might be willing to break with their leaders to work with the president on legislative priorities, he implied.

“At the end of the day, [President Trump] recognizes that he has a bold and robust agenda that he is trying to enact ... and he is going to get the votes from wherever he can,” Spicer said.

This story has been updated with comment from Sean Spicer.

CORRECTION: An earlier version of this story misstated that Trump had not previously blamed members of the House Freedom Caucus in public for the GOP health care bill’s demise.