The U.S. Supreme Court has agreed to review the legality of President Donald Trump's executive order banning travelers from largely majority-Muslim countries.

At the heart of the Trump administration's legal case is a 1972 Supreme Court decision that recognized sweeping executive authority over immigration. If Trump ultimately wins on the merits, it is likely to be because a majority of the Court shares his administration's interpretation of the precedent set in a case called Kleindienst v. Mandel.

In 1969 a Belgian journalist and self-described "revolutionary Marxist" named Ernest Mandel applied for a nonimmigrant visa to the United States in order to give a speech at Stanford University.

Mandel's application was denied because, under the terms of U.S. immigration law, "aliens shall be ineligible to receive visas and shall be excluded from admission to the United States" if they "write or publish" in support of "the economic, international and governmental doctrines of world communism."

Federal law gave the attorney general the power to grant waivers from this restriction on a case-by-case basis, but no such waiver was given to Mandel.

Mandel then joined with six U.S. citizens, all of them university professors, in a lawsuit filed in federal court. They argued the First Amendment protected the right of American scholars to "hear [Mandel's] views and engage him in a free and open academic exchange." The constitutional right to listen and speak to Mandel in person, the professors argued, trumped the government's power to keep Mandel out of the country.

The Supreme Court, however, ruled for the government. "Plenary congressional power to make policies and rules for exclusion of aliens has long been firmly established," the Court observed. And Congress has delegated much of that power to the executive branch. "We hold that when the Executive exercises this power negatively on the basis of a facially legitimate and bona fide reason," the Court said in Kleindienst v. Mandel, "the courts will neither look behind the exercise of that discretion, nor test it by balancing its justification against the First Amendment interests of those who seek personal communication with the applicant."

Writing in dissent, Justice Thurgood Marshall accused the majority of bending over backwards in favor of the government. "Even the briefest peek behind the Attorney General's reason for refusing a waiver in this case would reveal that it is a sham," Marshall wrote. Yet the majority "demands only 'facial' legitimacy and good faith" from the government, "by which it means that this Court will never 'look behind' any reason the Attorney General gives. No citation is given for this kind of unprecedented deference to the executive, nor can I imagine (nor am I told) the slightest justification for such a rule."

As far as Marshall was concerned, "Americans cannot be denied the opportunity to hear Dr. Mandel's views in person because their Government disapproves of his ideas."

The Mandel ruling is now at the center of the legal battle over Trump's travel ban. Specifically, it is at the center of the battle over whether the federal courts should take Trump's various comments, tweets, and campaign statements disparaging Muslims into consideration when weighing whether or not the travel ban was motivated by illegal anti-Muslim animus.

According to the Trump administration, because the president took this executive action in the name of national security, his order is "legitimate and bona fide" and therefore fully satisfies Mandel. In fact, the administration insists, under Mandel the travel ban is owed extensive deference from the courts.

By contrast, the parties challenging Trump's executive order insist that Mandel should be read more narrowly. They argue that the courts must "look behind" Trump's purported justifications and examine his history of anti-Muslim statements. That history, they argue, demonstrates that the travel ban was designed to serve the unconstitutional purpose of heaping official disfavor on Muslims.

The trouble for the legal challengers, however, is that, as Justice Marshall noted in his dissent, Mandel comes out against the "look behind" approach and favors broad executive discretion. In other words, like it or not, Mandel would seem to be a precedent in support of the Trump administration in this case.

But the legal challengers have precedent on their side, too.

In the 2005 case of McCreary County v. ACLU of Kentucky, the Supreme Court made it clear that the judiciary should look behind the government's purported rationale if the government is suspected of trying to favor (or disfavor) a particular religion in violation of the Establishment Clause of the First Amendment.

"Scrutinizing purpose does make practical sense," the Court said in McCreary County, "where an understanding of official objective emerges from readily discoverable fact, without any judicial psychoanalysis of a drafter's heart of hearts."

To find those facts, the Court in McCreary County endorsed what it called a "purpose inquiry," in which judges are directed to look behind the official government explanation and examine "traditional external signs that show up in the 'text, legislative history and implementation of the statute,' or comparable official act."

According to the parties challenging Trump's travel ban, when you apply McCreary County to the travel ban, you get the green light for exacting judicial scrutiny against Trump's negative statements about Muslims.

Until now, the lower courts have mostly leaned in the direction of McCreary County, rather than in the direction of Mandel, which is why Trump has mostly been losing. But there is no guarantee the Supreme Court will move in that direction.

When the justices finally hear arguments on the merits, both of these precedents are likely to be in play. And at that point the outcome is anybody's guess.