In his farewell address to the nation in 1989, President Ronald Reagan told the story of a Navy sailor patrolling the South China Sea who came upon a “leaky little boat” crammed with refugees from Indochina trying to find a way to America.

“Hello, American sailor,” a man in the boat shouted up to the Navy vessel. “Hello, freedom man.” Reagan couldn’t get that moment out of his mind because of what it said about what the United States meant — to those who live here and to the rest of the world.

But history reveals that even as the United States moved from the restrictive immigration policies of a century ago to Reagan’s advocacy of an open door to refugees, public opinion has oscillated. President Trump’s move Friday to bar entry into the United States for residents of seven majority-Muslim countries harks back to a period when the U.S. government regularly banned immigrants and refugees from countries whose people were considered inferior, dangerous or incompatible with American values.

Trump’s executive action marks the first time a president has sought to bar people because of their nation of origin — or their religion, as only Muslim-dominated countries are included in the order — since the 1965 Immigration and Nationality Act scrapped national-origin quotas, putting the focus instead on immigrants’ skills and personal connections to Americans.

“This is a paradigm shift,” said David Bier, who studies immigration policy at the Cato Institute, the libertarian think tank. “This is an explicit rejection of the approach that George W. Bush and Barack Obama embraced, in which a big part of the war on terror was to bring in allies, to prove we’re not waging a war on Islam and to show that we’re an open society toward Muslims.”

The history of this nation of immigrants is one of open doors and gates slammed shut, of welcoming words like those engraved inside the pedestal of the Statue of Liberty (“Give me your tired, your poor, / Your huddled masses yearning to breathe free, / The wretched refuse of your teeming shore”) and of generations of politicians and activists proclaiming that American values would be undermined by a new influx of foreigners.

“Both open and restrictive refu­gee policies have gotten very high approval in polls through the years,” said Roger Daniels, a historian of U.S. immigration and professor emeritus at the University of Cincinnati. “In times of trouble, nativist policies — what Trump would call ‘America First’ — get more attention. Since colonial times, there’s been a strong strain of nativism that either dominates or is just ignored.”

“America must remain American,” President Calvin Coolidge said in 1924 as he signed into law a measure that ended the biggest wave of immigration in U.S. history. The new law used the then-popular pseudoscience of eugenics to set drastic limits on entry by groups the government considered “socially inadequate” — mainly Italians and Eastern European Jews.

That same year, that same president declared the Statue of Liberty a national monument. And four decades later, President Lyndon B. Johnson traveled to the statue to sign the act that is still the basis of U.S. immigration policy. The 1965 law, Johnson said, “corrects a cruel and enduring wrong. . . . for over four decades, the immigration policy of the United States has been twisted and distorted by the harsh injustice of the national origins quota system. Under that system, the ability of new immigrants to come to America depended on the country of their birth. Today . . . this system is abolished.”

Bier and others argue that the Trump order is illegal because it seeks to restore national origin as a factor in deciding who gets into the country. The Trump administration contends that the president has the authority to suspend entry for any group he finds detrimental to the national interest.

However that issue plays out in the courts, the debate over how to decide who comes to the United States stretches back centuries and has been a hot issue in presidential and local elections for several decades. Although every president since Franklin D. Roosevelt has supported admitting refugees fleeing political and religious persecution, those presidents also struggled to defend such policies against strong voices advocating tighter limits on newcomers.

(McKenna Ewen/The Washington Post)

Near the end of World War II, Roosevelt, after a long period of resisting pleas by American Jews to admit European Jews fleeing the Nazis’ program of extermination, decided to allow 1,000 refugees into the country and put them at an Army base in Upstate New York.

“That’s the beginning of the presidential authority to interfere with immigration policy,” Daniels said. “And it has continued ever since.”

Trump’s focus on blocking people from predominantly Muslim countries and carving out openings for Christians fleeing those countries “is at variance with everything we’ve done since Roosevelt, Truman and Eisenhower built our approach to refugees,” Daniels said.

Perhaps paradoxically, the gates to the United States have tended not to tighten during wartime. In the late 2000s, George W. Bush increased the flow of refugees into the country as a way to thank people who had helped U.S. forces in Iraq and Afghanistan, and to demonstrate that he was serious about attacking terrorism rather than Islam.

Economic hardship has sometimes led to louder calls for more restrictive immigration and refu­gee policies, historians say, but surges of nativist sentiment have emerged more from cultural backlash than from hard times or wartime. The restrictive 1924 law, for example, “came about in the Roaring Twenties, a time of great economic growth,” Bier noted.

From the late 19th century through the 1930s, popular belief in eugenics, along with rivalries among religious groups, fed movements aimed against Catholics, Jews, Eastern Europeans, Asians and Africans.

“It’s really the civil rights movement of the 1960s that changed the approach,” Bier said. After the Civil Rights Act passed in 1964, ending legal segregation and banning employment discrimination based on race, religion or national origin, the idea of admitting immigrants based on where they came from seemed anachronistic.

In the 1980s, the immigration debate centered on illegal immigration; policies of that period were driven by the idea that expanding legal pathways into the country might curb the flow of illegal entrants. It didn’t work; the battle over illegal immigration continued.

Some anti-immigration activists argued that the problem was not limited to illegal immigration but extended to all newcomers. Those activists focused on crimes committed by noncitizens, and Trump campaigned on that theme, highlighting stories of Americans whose loved ones had been killed by immigrants.

That approach won support from activists who have long sought not only a wall along the U.S.-Mexican border but also sharp cuts in legal immigration. Mark Krikorian, executive director of the Center for Immigration Studies, which seeks “low-immigration” policies, welcomed Trump’s latest moves, but noted that executive action is not enough. A “reduction in legal immigration — which is the most important objective from a jobs or welfare or even security perspective — has to come from Congress,” Krikorian said in a blog post.

Bier said, “We’re seeing populism take control of immigration policy for the first time” since World War II. “You don’t have leaders in politics right now who are willing to say that we welcome people fleeing the enemies of the United States.”

Reagan began and ended his farewell speech with powerful pleas for the country to open its arms. The “shining city upon a hill” that he wanted America to be was, he said, a place “teeming with people of all kinds living in harmony and peace. . . . And if there had to be city walls, the walls had doors and the doors were open to anyone with the will and the heart to get here.”