President Trump is obsessed with loyalty. From his constant, unremitting assault on his own attorney general, Jeff Sessions, to his critique of an anonymous op-ed in the New York Times this month, Trump is constantly on guard against disloyal subordinates, viewing such behavior as deeply damaging not just to him, but to the United States.

This idea that loyalty, whether to political leaders or policies, is crucial to national security has a deeply problematic history in the United States.

In March 1947, President Harry S. Truman matched exaggerated rhetoric about defending democracy abroad with draconian executive actions intended to defend it at home. Truman’s Loyalty Program, launched with Executive Order 9835, was justified as a national security measure to protect a government perceived to be vulnerable to threats from within.

Although the loyalty program was justified as a measure to safeguard democracy, sweeping enforcement took it far beyond its purported purpose. Ultimately, the measure endangered democracy by creating a climate of fear that stifled many voices — voices that might have led to wiser policy. Trump’s intolerance of dissent may have equally disastrous consequences, not only muzzling Americans’ freedom of expression, but also resulting in policies that make the nation less strong and less safe.

Truman’s executive order began with the assertion that “each employee of the Government of the United States is endowed with a measure of trusteeship over the democratic processes which are at the heart and sinew of the United States.” It explained that all federal workers were expected to demonstrate “complete and unswerving loyalty” to the United States, as “the presence within the Government service of any disloyal or subversive person constitutes a threat to our democratic processes.”

This premise might have sounded reasonable to many Americans, but it spawned widespread and repressive enforcement actions. Loyalty and subversion were conceived in the broadest possible manner, and the order applied to populations far beyond what most would consider to be government workers.

From 1947 to 1951, about 4 million employees were checked, with about 20,000 cases considered in more detail. Nine thousand government workers faced charges, with hearings held for about 3,000. A total of 378 people were dismissed or denied employment for perceived disloyalty.

Federal employees in the armed forces, the State Department (especially the Foreign Service) and various other government institutions — including the Justice Department and the Treasury Department — were significantly affected by the legislation. They risked losing their livelihoods, their reputations and in some cases their families because of often-unfounded accusations.

But the impact of the hunt for disloyal Americans extended far beyond the federal government, percolating down to federally funded institutions at state and local levels. Hundreds of thousands of public employees nationwide had to swear their loyalty or face the consequences.

Public universities, for one, were profoundly affected by Executive Order 9835. In California, for example, the University of California and the California State University systems required all employees to take a loyalty oath. Many professors denounced it as a direct attack on academic freedom and freedom of thought more generally.

One of the bluntest weapons wielded at both national and local levels was the Attorney General’s List of Subversive Organizations (AGLOSO). First drawn up in December 1947 and regularly updated thereafter, this list consisted of more than 500 organizations that included American Communist organizations, fascist organizations and terrorist organizations, such as the Ku Klux Klan. But it also included professional associations; progressive groups; associations of African Americans, including the National Negro Congress, the United Harlem Tenants organization and the United Negro and Allied Veterans of America; and Jewish organizations, including the American Jewish Labor Council, Jewish Peoples Committee and School of Jewish Studies in New York City. In 1951, the Supreme Court ruled that no group could be added to the list without a hearing, but by then many organizations and their members had suffered irreversible stigmatization.

The government considered “foreign” and immigrant groups suspect, as well as any organization identified as seeking to “alter the form of government of the United States by unconstitutional means.” That meant targeting labor unions. Scientists were suspect. Libraries and school districts were affected. Books were banned, as were journals and textbooks — not least in the new and distrusted discipline of “social science.” Public schools were instructed not to teach certain subjects and directed to teach others.

Government agencies defined “subversives” broadly and ambiguously. Homosexuality, for instance, was deemed to be indicative of subversive behavior. Between January 1947 and November 1950, the government took action in 574 cases of suspected “sexual perversion.” Between 1947 and 1951, the CIA alone dismissed more than 70 people for reasons of “sexual perversion.”

This assault on difference and dissent was not done stealthily or undemocratically; it was enacted with due process and the involvement of all three branches of government. The Truman administration crafted intricately detailed prescriptions as to how its directives should be enforced. A sheaf of government documents and legal articles were published laying out the protocols of the loyalty boards that would be employed and the impact on public employees.

But the democratic bureaucracy and corresponding legal apparatus created to implement Executive Order 9835 should not be confused with the democratic principle of respect for individual rights and freedoms, which were trampled on in the process. This highly illiberal democracy existed within a democratic framework.

After Congress passed the 1950 Internal Security Act over his veto, Truman expressed disdain for Joseph McCarthy and others whom he accused of waging a “relentless attack” on government employees in the name of national security. “It is one of the tragedies of our time,” he declared, “that the security program of the United States has been wickedly used by demagogues and sensational newspapers in an attempt to frighten and mislead the American people.”

But the fact remains that Truman’s own loyalty program was designed exactly for this purpose — to demand loyalty through intimidation and fear. As a legal scholar observed in 1952, “It is true that the current loyalty oaths do not suppress free expression by directly outlawing any socially useful belief, expression, or association. But the benefits of free expression are as much lost when it is sacrificed through fear as when it is arrested by outright suppression.”

Trump is no Truman. It seems doubtful that Trump, for instance, would have opposed McCarthy. But while Truman opposed demagoguery, he was also prepared to blithely ruin the lives of hundreds of Americans and to intimidate hundreds of thousands more. What might a president obsessed with loyalty not only to government but, more important, to himself do to enforce it?