Sitting next to Sen. Dean Heller, an opponent of the Senate Republicans’ bill replacing the Affordable Care Act, at lunch on Wednesday, President Trump mused: “He wants to remain a senator, doesn’t he?”

During the luncheon, Trump also issued a veiled threat that he would campaign against Republicans who obstructed his agenda. The lunch came on the heels of news that the White House has courted a number of potential primary challengers to Sen. Jeff Flake, an Arizona Republican who at times has criticized Trump and refused to endorse him during last year’s campaign.

The president uses these threats to try to bend members of Congress to his will and mete out revenge against those who dare challenge him. But taking personal battles to party primaries is a hazard with the potential to undermine the president’s legislative agenda. Nearly 80 years ago, another New Yorker, Franklin D. Roosevelt, gambled his prestige on an attempt to purge conservative dissenters from the Democratic Party — and lost.

The misguided campaign demonstrates the danger of a president allowing emotion and an inflated sense of his power to overcome his better political judgment. Roosevelt’s failed purge energized and emboldened conservatives in both parties; they coalesced into a majority coalition in Congress that thwarted his domestic agenda for the remainder of his presidency, stopping the New Deal in its tracks.

Roosevelt’s efforts to shape the Democratic Party were not abnormal. Modern presidents play a prominent party leadership role by recruiting candidates, setting the partisan agenda and boosting supportive lawmakers. But when hubris, vengeance and frustration, rather than cold political calculation, drive party-building efforts, it can backfire and harm both the party and the president.

For all of Roosevelt’s achievements and political skill, he was not immune to arrogance occasionally clouding his political judgment. In 1936, Roosevelt crushed Kansas Governor Alf Landon by more than 11 million votes and the president believed this overwhelming victory gave him license to pursue his progressive agenda. However, despite Democratic control of Congress, Roosevelt’s perceived mandate was illusory.

A recession in 1937 triggered criticism of Roosevelt’s economic policies. Many conservative Southern Democrats also suspiciously eyed Roosevelt’s now infamous “court-packing” plan, which called for an expansion of the Supreme Court from 9 to as many as 15 Justices — meaning Roosevelt would immediately nominate six new justices. By packing the court with Roosevelt appointees, the proposal transparently aimed to remove an impediment to Roosevelt’s agenda after the court struck down such New Deal programs as the National Recovery Act and the Agricultural Adjustment Act.

To conservative senators like Millard Tydings of Maryland and Ellison Smith of South Carolina, both Democrats, the court-packing plan, along with Roosevelt’s reorganization of the executive branch, smacked of dictatorial impulses. They and their allies were determined to prevent Roosevelt from making the state more powerful and intrusive in the lives of Americans than it had ever been before.

Roosevelt found it especially galling that these Democrats opposed his agenda on Capitol Hill while embracing his administration’s popular programs on the campaign trail. This subterfuge drove Roosevelt to wage a primary campaign against potentially vulnerable conservative Democrats. “They have no idea what’s going to happen,” the president promised political confidant James Farley. “They’ll be sorry yet.”

While pique motivated Roosevelt, he also believed that as the leader of the Democratic Party, he needed sharpen the party’s ideological consistency and ensure that it clearly stood for a set of principles. As the president charged during a fireside chat in June 1938, “An election cannot give a country a firm sense of direction if it has two or more national parties which merely have different names but are as alike in their principles and aims as peas in the same pod.”

However, many of Roosevelt’s most trusted advisers, less blinded by ire and frustration, counseled that the purge was a mistake. “Boss, I think you’re foolish,” Farley lamented. The move alarmed the press. Many editorial writers branded it “Roosevelt’s Purge” — a phrase recalling the murders of members of the Communist Party at the hands of Soviet leader Joseph Stalin a few years earlier. Others accused the president of trying to create a party of “Hitler yes men,” or further increase his executive powers.

But despite the warnings and negative coverage, Roosevelt plunged ahead. As the summer progressed, he boarded a 10-car train for a trip through the South. In states like Kentucky, Oklahoma, Arkansas and Texas, Roosevelt pummeled his conservative opponents and sang the praises of their more liberal primary challengers.

Yet for all of Roosevelt’s confidence, charisma and popularity, his purge failed. While the president and his programs were popular throughout the nation, residents of the states Roosevelt visited resented his interference. As the campaign progressed, Roosevelt discovered that his chosen candidates were no match for the entrenched and well managed political machines that many of his targets had at their disposal.

It was not Franklin Roosevelt’s finest hour. As his handling of World War II would demonstrate, Roosevelt was at his best when he could optimistically communicate thoughtful arguments about issues he believed were in the national interest. But when he allowed hubris and a thirst for vengeance to override those natural instincts, as in the case of the court-packing plan or the attempted purge of 1938, he stumbled.

The failed purge had long-lasting consequences for Roosevelt’s agenda. That fall, the GOP gained 81 seats in the House and eight in the Senate. When the new Congress convened in 1939, the deep reservoir of liberal support that had propelled the New Deal’s early legislative success had vanished. Instead, the president confronted a newly assertive conservative coalition determined to resist any and all of his proposals. While the conservatives lacked the support to roll back the core of the New Deal, neither could Roosevelt advance any new programs. Dreams like national health insurance were dead.

Politics have changed immensely since our 32nd president inhabited the White House. Yet presidents still strive to construct a party supportive of their agenda. As Trump has discovered, presidents are also still frustrated by dissident members of their own party. Wise presidents, however, learn to accept that members of Congress have different interests, and sometimes dissent from party positions. Those that don’t run aground, as Roosevelt learned.

If Trump follows his path, the consequences could be devastating. A brutal primary battle could hand the seats held by Heller and Flake to the Democrats. Or they might survive, returning to office newly liberated to oppose the president at will, as Roosevelt’s opponents were after 1938. Either way, Trump will lose, and his agenda will languish.