As toxic as American democracy has become in 2024, it’s far more functional today than it was the 1800s when the shadowy bosses of political machines vied for power and profit. Until recently, modern politics has been comparatively civilized thanks to determined reformers who established laws and institutions that reduced corruption and promoted democratic principles.

This history reminds us of the importance of safeguards for the functioning of democracy and highlight the danger of Donald Trump’s plans to dismantle them with his 2024 presidential bid.

The trouble started in the 1820s when Andrew Jackson rebelled against the political establishment. After winning the presidency in 1828, Jackson dismissed experienced federal employees and replaced them with partisan loyalists, a practice known as patronage. “To the victors belong the spoils of the enemy,” gloated Jackson’s ally, Sen. William Marcy of New York. The senator’s boast became a platitude and provided a label for the politics of the era: the spoils system.

The spoils system propagated like a pernicious weed. Leaders of the Whig Party denounced Democratic Party patronage, but practiced it themselves when they came to power in the 1840s, as did the Republicans who supplanted the Whigs in the 1860s, starting with President Abraham Lincoln. Federal patronage practices were replicated by state and city governments, infecting the entire political order.

Patronage appointees were often unqualified, from district attorneys and police commissioners to street cleaners and mail carriers. “The Post-office, from top to bottom, is cursed with this evil of patronage,” the New York Times in 1873. “A large number of persons engaged in the difficult work of delivering, sorting, and carrying letters, or deciphering addresses, and finding out mistaken ones, have not the slightest skill or experience in the business. They are put there merely to oblige political patrons.”

But the incompetence of civil servants wasn’t the nastiest feature of the spoils system. The people who made the hiring decisions were far more dangerous, for their ability to distribute plum jobs to underlings gave them tremendous power to bend government to their will. Most of the decision-makers weren’t even elected officials. They were the ruthless leaders of partisan organizations known as political machines. States and large cities typically had at least two rival machines, one for each major party. The machines nominated candidates for federal, state, and city elections and marshaled voters on Election Day. Elected officials repaid their patrons by hiring whomever the bosses recommended.

The stakes were high, and the machine bosses used every tool at their disposal to ensure victory. They bribed voters with cash and alcohol, dispatched thugs to intimidate opponents at polling stations, performed favors for corporations in exchange for campaign donations, paid newspapers to shill for their candidates, and exploited ethnic divisions to galvanize voters. Elections were raucous high-turnout affairs, often tainted by fraud and violence.

With great power came great corruption. The bosses employed countless schemes to exploit their authority for profit. They took bribes from job applicants and kickbacks from companies seeking franchises and land rights. Some invested in real estate and then funneled public investment to the area to increase property values. William Tweed, boss of the notorious Tammany Hall, embezzled tens of millions from New York City’s treasury in the 1860s. The corruption started at the top but permeated all the way down. Customs officials took bribes from importers. Building inspectors received payoffs from landlords and developers. Vice cops shook down casinos and brothels.

The perpetrators of such rackets were rarely held accountable because the authorities—judges, prosecutors, inspectors, and police—were loyal to the machines. But tenacious journalists and courageous dissidents did occasionally expose government corruption.

Periodic scandals drew public outrage and fueled reform movements. After the New York Times exposed Boss Tweed’s plundering in 1871, prominent New Yorkers formed a committee to investigate Tammany Hall. Subsequent graft scandals in President Ulysses S. Grant’s Administration galvanized a national movement to clean up the federal government.

Reformers devised a number of initiatives to loosen the bosses’ grip on power, including secret ballots, voter registration, primary elections, and anti-graft laws. The most successful strategies targeted the source of the bosses’ influence: the power of patronage. One of the landmark reforms, the Pendleton Civil Service Reform Act of 1883, instituted merit exams for federal jobs and prohibited demotion or dismissal without cause. The original rules applied to a small subset of employees, but subsequent reclassifications expanded to the protections to cover 90% of the federal workforce.

The Pendleton Act only pertained to federal employees, however. State and city governments proved even more difficult to fix. It took decades for reformers to wear down resistance from entrenched political machines and establish civil service laws similar to the Pendleton Act at state and local levels.

In 1930, New York governor Franklin D. Roosevelt initiated an anti-corruption investigation that uncovered rampant graft in New York City, including a shocking police conspiracy to frame innocent women as prostitutes. After the Tammany-backed mayor resigned in disgrace, his successor, Fiorello La Guardia, instituted civil service rules that finally ended Tammany Hall’s 80-year reign. Similar clashes took place across the country well into the 20th century.

Ultimately, the reformers won the war. The civil service reforms worked. Deprived of the power of patronage, the political machines that had ruled the nation for over a century gradually withered away. Elections became more peaceful and democratic. The press became more objective. Partisanship ebbed, and corruption declined.

President Donald Trump has ignored the principles of the Pendleton Act in unprecedented ways. As President, he made clear that, in his eyes, career civil servants weren’t apolitical bureaucrats but agents of the so-called “” who sought to defeat him. And in the final months of his presidency, Trump issued an executive order known as “” that exempted a new class of federal employees from civil service protection. His aides boasted that the reclassification would affect more than . Documents obtained under the Freedom of Information Act indicate that the administration’s plans were . At least one agency, the Office of Management and Budget, planned to apply the new category to of its staff.

Trump’s term ended before much damage could be done, but he has promised to revive and expand the plan if he wins reelection in November. If elected, he also intends to tell prosecutors and federal agents, traditionally independent, to “” his opponents, starting with his predecessor whom he deemed, “the most corrupt president in the history of the United States of America, Joe Biden, and the entire Biden crime family.”

To the victors belong the spoils of the enemy.

Once these dams of civil service protection have been breached, others may not be able to resist the urge to follow suit. As guardrails fall across the country, corruption is likely to follow, as it did in the 19th century. If a new spoils system becomes entrenched, it could take decades to uproot, a tragedy for liberals and conservatives alike. Then Americans would discover, or rather rediscover, how toxic and dysfunctional a lawless democracy can be.

Michael Wolraich is the author of (Union Square & Co., 2024).

Made by History takes readers beyond the headlines with articles written and edited by professional historians. . Opinions expressed do not necessarily reflect the views of TIME editors.