The House of Representatives has become The Lord of the Flies. Republicans, despite being in the majority, lost a vote on major legislation (the Farm Bill) put forward by its leaders. The leadership might also lose control of the floor agenda, through an unusual maneuver that would force a series of uncomfortable votes on immigration. The speaker of the House could get booted in a nearly unprecedented insurrection right before the midterm elections. Moderates on the left and hardliners on the right are in open revolt.

This is not how Paul Ryan wanted to leave office. But his decision to retire at year’s end, prompted by a desire to protect himself from a tough election, caused this debacle—and it’s imperiling the political project he spent a career building.

Ryan, who was elected in 1998 and became speaker in 2015, has long advocated for cutting programs for the poor, an agenda he cloaks in the language of “reform” and justifies with performative concern over the budget deficit. The more credulous members of the media too often bought that act. But his was always just a reverse–Robin Hood redistribution project, an Ayn Randian anti-government paradise where the welfare state was quietly strangled for the benefit of the wealthy.

Ryan waited his entire career for a right-wing president willing to enact this agenda. He got one in Donald Trump. But then he discovered the ugly truth—the public hated his ideas and would recoil if he ever tried to put them into effect. When Ryan went after Obamacare, his own party struggled to pull the trigger on culling millions of Americans from the insurance rolls; eventually they abandoned the repeal effort. On taxes, he claimed to champion reform but ended up just giving corporations a big cut, while not making the code even a little bit simpler. And Ryan didn’t prepare for the propulsive power of identity-based issues like immigration to rip his caucus asunder.

When Trump issued his withdrawal of the Deferred Action for Childhood Arrivals program last September, Ryan put Republican members from across the ideological spectrum on immigration in a room together and asked them to come up with a solution that could win broad support. But it was obvious from the beginning that there was no compromise to be made; Ryan just didn’t want to take any leadership and be held responsible for the fallout. The effort fizzled.

Ryan announced his retirement in April. At the time, he pulled out an internal poll showing him up on his top Democratic challenger, ironworker Randy Bryce, by 21 points. But Democratic polling showed a much closer race, and the announcement came on the heels of a Republican upset in a Pennsylvania district that was much redder than Ryan’s. Either he didn’t want to campaign in what looked like a tough election environment, or, seeing Republicans’ uphill battle to retain the House, didn’t want to stick around long enough to lose his speakership to a Democrat.

The retirement sent a message to every House Republican: It’s every man for himself. Some responded by retiring, too. Others decided they had to save their political skins by rejecting the conservative agenda. Still others saw holding onto conservative ideals as more important than keeping the majority.

This played out in disastrous fashion for the GOP over the past week. Republican Congressmen Jeff Denham of California and Carlos Curbelo of Florida started a discharge petition to circumvent Ryan and force votes on four separate immigration bills—including the DREAM Act, which creates a path to citizenship for immigrants brought to the U.S. as children. Discharge petitions, which require the support of a majority of congressmen, almost never work because party leaders openly threaten their members to discourage them from signing on. Ryan’s retirement, however, has emboldened those more interested in self-preservation: The discharge petition is just five Republican votes away from a majority, assuming all Democrats support it. Denham is confident he can meet that threshold.

The discharge petition sparked a furious counter-move on the hard right, who prefer the mass deportation policies of Trump’s Immigration and Customs Enforcement. They took a hostage: the Farm Bill, typically a perfunctory (if deeply flawed) effort that unites agricultural subsidies and the food stamp program. The Freedom Caucus vowed to reject the Farm Bill without a deal on immigration that avoided a DREAM Act vote, in favor of a far more punitive measure. When no deal emerged by Friday, they sunk the Farm Bill; it failed 198-213.

Ironically, this ended up derailing one of Ryan’s core welfare reform ideas: adding stringent work requirements to the food stamp program, which would have thrown millions of people off the rolls and suppressed wages. Freedom Caucus members support shrinking the welfare state, but they voted against the bill anyway.

In many ways, the defeat was more symbolic than substantive; the Senate wasn’t passing a farm bill with those work requirements anyway. But it revealed how thoroughly the Republican leadership has lost control. They have no ability to tramp down moderates on immigration who are trying to save their jobs this fall, or hard-right Freedom Caucusers who kept themselves in line over the tax bill but now see no reason to keep quiet. “This is the problem when you have a lame duck speaker who announces he’s leaving eight months in advance,” a senior Republican source told Politico. “He can make calls to members to urge them to vote for something, but who will care?”

Ryan’s speakership has become untenable. House members are roping in Trump on a plan to depose Ryan this summer, putting the House in the hands of Majority Leader Kevin McCarthy. It’s unclear whether the Freedom Caucus would go along. They have circulated a letter to get Jim Jordan, one of their leaders, to run for speaker, so the McCarthy plan to bring order to the House may only create greater disorder, and no speaker in charge for months.

The next six months before the midterms will put the ungovernable House on display. They still have to pass a budget in September to avoid a government shutdown. There can be no greater boost to Democratic hopes to win the midterms than a Republican government unable to fulfill such basic tasks.

You can lay that at the feet of one man. Ryan will likely leave office with Nancy Pelosi or another Democrat taking his speaker’s gavel. His own seat, in Republican hands for decades, is now a toss-up. He achieved almost none of the vaunted “reforms” he spent a lifetime promoting: Social Security, Medicare, food stamps, and countless other policies remain mostly the same as when Ryan entered office. Sure, Republicans got their tax cuts—that’s no feat with a caucus of tax-cutters—but Ryan imagined the overthrow of the welfare state and got next to nothing. However he exits the House this year, it’s sure to be an appropriately ignominious end to his political career.