The party of Abraham Lincoln once embraced equality and opportunity for all. Now Republican president-elect Donald Trump appears poised to take the netherworld of alt-right white nationalism mainstream.

This is a terrifying moment in history. It seems possible that American democracy may perish. But the situation is not unprecedented.

In the 1880s and 1890s, extremists in the Republican party also threatened the future of the US. Just when it seemed the extremists’ control of the government was complete, their political machinations, propaganda, and demonization of their opposition fueled a dramatic backlash. Voters backed leaders who restored the Republican party to its traditional principles and, together, they created the progressive era.

With Republicans in control of the White House as well as both houses of Congress, it may seem as if the party has little need to engage in the kind of self-reflection that might lead to reform. But if history is any indication, the party’s shift toward the extreme right may backfire—eventually.

The birth of the GOP

At the moment, the three major factions of the GOP are united only in their determination to control the government, although different factions want that power for different reasons. Elites want to cut taxes and stop government regulation of business. Evangelicals want to make America a Christian nation. And alt-right voters want to purge the rights of minorities and women.

Today’s party would be unrecognizable to the Republican party of the 1850s, which was formed in an effort to guarantee that all hardworking Americans would have equal opportunities. In the run-up to the Civil War, early Republicans watched a cabal of rich slave owners take over the Democratic party and use the government for their exclusive benefit. Increasingly, hardworking men at the bottom of the economic ladder worried that if slave owners stacked the legal deck against them, workers would never be able to rise.

Democrats in this era tended to see the economy as a zero-sum game in which the wealthy and the poor would always be locked in conflict. But Republican leader Lincoln articulated a new vision for America.

Lincoln conceived of the nation as one of social and economic harmony, with those at the bottom providing the engine for unlimited economic growth.

Lincoln conceived of the nation as one of social and economic harmony, with those at the bottom providing the engine for unlimited economic growth. So long as workers had access to resources and education, they would produce more than they would consume, and thus would support shopkeepers and small businessmen in the middle of the economic ladder. Those people, in turn, would support industrialists and financiers at the top, who would then hire people who were just starting out. “Until every beggar is provided with a coach and six,” wrote the Republican Chicago Tribune, “there will be no such thing as overproduction…. We shall never get out of business in this world.” As standards of living improved, people would treat each other better, and social conflicts would decrease.

During the Civil War, Republicans followed through on this vision. They created an active government that provided homes and education for poor men, protected all national industries, and eventually legally freed Southern slaves. Under this new system, the nation thrived. The government fielded an army and navy that eventually included more than a million men, assumed a national debt of more than $6 billion, and jumpstarted an industrial economy. By the time the war ended, the Americans who had defended the US government loved the Republican system.

Barreling toward self destruction

Over the course of the years following the Civil War, however, Republicans’ economic vision underwent a drastic shift, propelled by the fear that the nation’s new labor unions would destroy economic harmony and foment an “us-versus-them” sentiment among Americans. Republicans turned against organized workers and abandoned the idea of promoting equality at the bottom of the economic scale. They turned their idea of economic harmony into a justification for supporting industrialists, who were the nation’s job creators.

By the 1880s, Republican policies had created an economy that looked much like today’s. The nation’s wealth had concentrated among the Carnegies and Rockefellers of the country. The majority of Americans were left sweating in factories and fields, living in poverty or on the brink of it.

Republicans who had once championed hardworking Americans argued that favoring any special interests would destroy economic harmony.

Democratic voters argued that rather than favoring industrial barons, congressmen should keep the economic playing field level by protecting workers and farmers. But Republicans who had once championed hardworking Americans retorted that favoring any special interests would destroy the very economic harmony on which an expanding economy depended. Protecting business, they argued, protected everyone.

It was the Republicans’ fierce commitment to this principle, in spite of ample evidence that their policies were failing to improve the lives of working Americans, that would be the party’s undoing.

The war on compromise

The political tide began to turn in 1884 when Republican party operatives nominated James G. Blaine for president, who was popularly believed to be in the pocket of railroad corporations. Blaine lost to his Democratic opponent, Grover Cleveland, who called for government to curb its pro-business extremism and protect the opportunity of all men to rise.

Cleveland’s win horrified Republican leaders. They knew full well that increasing immigration, industrialization, and urbanization meant they would never again attract a majority of voters. It would be only a question of time until Democrats gained the power to readjust the economic policies of the country.

Convinced that they alone understood how to govern, Republican leaders launched a war on the Democrats. They charged Cleveland with stealing the election, and in 1888, they drummed businessmen to funnel money into the Republican war chest. In that year’s election, the Republican candidate Benjamin Harrison lost the popular vote by 100,000 votes, but a last-minute shift in the Electoral College put him in the White House. Republicans also took the House and Senate for the first time since 1875.

Once in power, Republicans operatives did everything they could to keep themselves there by gaming the system.

Once in power, Republicans operatives did everything they could to keep themselves there by gaming the system. First, they added six new western states to the Union from 1889-1890, trying to guarantee that Republicans could hold the Senate for the foreseeable future and swing the Electoral College to Republicans. They replaced partisan color-coded ballots with secret, impartial ballots that required a voter to know how to read, then warned that continued Democratic victories only proved that the electoral system was rigged. They ginned up supporters to turn on the immigrants and organized workers who voted Democratic ballots, arguing that their calls for basic rights were in fact un-American demands for special treatment.

In the short term, the Republicans’ strategy worked. Republicans continued to hold at least one branch of the federal government, and they undermined faith in the electoral process. The popular mood turned dark and dangerous toward minorities and workers perceived to be “corrupting” the popular vote.

But in the long term, their strategy doomed the Republican ideologues. As they became increasingly convinced that they, and they alone, knew what was good for the country, Republican leaders shifted further and further right. They turned to religion, racism, and social Darwinism to justify their ideology and continue favoring business. They silenced alternative ideas. And as they manipulated the political system, they had less and less reason to compromise. They became convinced that compromise itself would kill the nation.

The rebirth of the GOP

But their extremism made them lose many of their own constituents, who feared Republican leaders were turning America into an oligarchy. Republicans managed one last decisive victory in the 1896 presidential election, when William McKinley beat Nebraska Democrat William Jennings Bryan. But this triumph was the last gasp of Republican extremism. Younger Republicans had already internalized the Democratic critique of economic policies that concentrated wealth at the top of society. These younger Republicans believed in the party’s traditional vision of economic and social harmony and adapted it to the industrializing nation. They wanted to use the government to educate the nation’s citizens and guarantee them clean cities, safe food, and fair wages.

These younger men also recognized the reality of the changing electoral map, which was increasingly urban and working class. Rather than following the party’s elderly leaders off an electoral cliff, they vowed to return the party to the original principles Abraham Lincoln had outlined 50 years before. Now that the gates were open for new voices and new ideas, American politics swung rapidly back to the left. Under Theodore Roosevelt and Wisconsin’s Robert La Follette, a new generation took the Republican party back to its original progressive roots.

Today’s Republican party is at this same critical juncture. It looks much like the party of the 1890s: run by extremists interested only in concentrating wealth and power at the top of society at a time when the majority of Americans want the government to level the economic playing field. The party’s leaders have stayed in power by playing to racist and sexist sentiments, and they have created a vicious right wing eager to destroy those whom they believe are un-American.

The chasm between the ideology of the radical political movement that has captured the Republican party and the needs of the diverse American majority is clear. And so we may yet be on the brink of another massive shift in the GOP—the kind that gave rise to Theodore Roosevelt and the progressive Republicans.

At the turn of the last century, extremists were forced back to the political fringes while younger politicians resurrected the vitality of the original Republican vision. They recognized that the nation could only develop and grow by protecting equality of opportunity for hardworking Americans at the bottom of the economic ladder.

Today’s moment looks much like 1888, when the Republican party claimed a mandate that it did not have to enact an ideology so extreme it created the conditions for an extraordinary backlash. In that backlash, younger Republicans adopted the Democratic idea that government should not privilege the wealthy. They wove that idea together with the traditional Republican vision of a social and economic web, and remade the government to defend equal opportunity in a time of dramatic change. In that era, the Republican party reformed itself and the nation not by tweaking its radicalism, but by reclaiming the ideas of its founders.