"Wow!" was his initial exclamation on Twitter after the court upheld his travel ban.

If the one-word response was joyful, it also reflected a nuanced reality. The court did offer Trump an unequivocal win, determining he was within his authority to protect the country's national security by limiting who comes into the country, just as the immigration debate reaches a boiling point. The 5-4 ruling essentially gave him a green light to express himself however he wishes -- even if that language veers into bigoted or racist speech -- without fear of legal repercussion.

But it did not uphold Trump's original suggestion, made as a candidate in 2015 , to enact a "total and complete shutdown of Muslims entering the United States." Nor did it uphold the original iteration of the ban, which was rushed out in the first weeks of the administration to widespread confusion and chaos.

Instead, the court upheld what Trump once dismissed as a "watered down, politically correct version," which came after two previous attempts were at least partially struck down.

It was, in part, a victory for a coherent, established agency process overseen by Trump's most hated Cabinet official, Attorney General Jeff Sessions. A year-and-a-half after the first attempt, there is little to indicate Trump is following those practices now.

'Vindicated'

Trump felt "vindicated" by the decision, his aides said in the immediate aftermath of the ruling, which came as the administration wages another chaotic battle on immigration, this time involving minors separated from their parents on the southern border. Inside the White House, Trump tweeted his "Wow!" response from his third-floor residence, where he was viewing coverage of the decision on television. Staffers from the White House counsel's office briefed him on the ruling.

In a statement and remarks after the ruling, Trump was triumphant.

"A tremendous success, a tremendous victory for the American people, and for our Constitution," is how he described the ruling in remarks from the Cabinet Room. "We have to be tough and we have to be safe and we have to be secure. At a minimum, we have to make sure that we vet people coming into the country."

"The ruling shows that all of the attacks from the media and the Democrat politicians are wrong, and they've turned out to be very wrong," he said.

The victorious moment came a year-and-a-half after the messy days of the original ban, which was drafted in haste by staffers without the usual input from the Justice Department. Instead, hardline aides Stephen Miller and Steve Bannon helped devise details of the order, including whether green card holders from the seven affected nations -- all Muslim majority -- would be permitted to enter the US. Chaos ensued at American airports, where border agents received little direction and were largely left to interpret the order themselves.

That original ban was swiftly blocked by courts.

A second version was also mired in legal trouble.

The third version, which was upheld on Tuesday, came after months of legal vetting by Justice Department lawyers. It includes two non-Muslim countries, North Korea and Venezuela, and was carefully written on strict national security grounds, which the majority of justices deemed did not exceed Trump's presidential authority.

It provided the highest-profile ruling yet for a court that now includes one of Trump's own selections, Justice Neil Gorsuch, whose place on the bench was a direct result of Senate Majority Leader Mitch McConnell's decision to refuse a vote on Merrick Garland, the nominee President Barack Obama put forward in the last year of his tenure. In a victory lap of sorts, McConnell's office posted a photo on Tuesday morning of the Republican senator shaking Gorsuch's hand.

A telling moment

JUST WATCHED Listen as lawyers argue travel ban case Replay More Videos ... MUST WATCH Listen as lawyers argue travel ban case 04:04

If the ruling was a lesson in the value of adopting an orderly policy process, it came at a telling moment. Trump's most recent executive order, meant to end the practice of separating migrant families at the border, has sown similar chaos among people trying to enter the US. It, too, was drafted hastily at Trump's demand. Miller, a young and outspoken policy adviser, has continued to play a central role.

Just as he publicly wavered over signing a revised travel ban, Trump has questioned in private the wisdom of his family separation order, which has yet to lead to mass reunions of minors and their parents. He has bemoaned the appearance of weakness in backing down from the harsh practice that led to outcry, even from his political allies.

At a rally in South Carolina on Monday, Trump suggested his initial political instinct was to allow the practice to continue.

"I had my own feeling when I heard them talking about the children," he said, continuing later: "I liked it. I said, 'Hey, this is fine for us.' "

Both issues cut to the heart of Trump's appeal as an immigration hardliner and his desire to quickly make good on his campaign promises. But they've also revealed the pitfalls of Trump's gut-driven approach to governing, one that relies on aides with scant federal experience to execute.

If the court victory on Tuesday was a "vindication" in Trump's mind, it was also vindication for Sessions, whose mere presence in rooms and on television has led to periodic fits of anger from Trump. The President has never forgiven his attorney general for recusing himself from the Russia investigation, but it was his agency's revisions and legal wrangling that have allowed the measure to persist.

On Tuesday, Sessions was in Los Angeles. When he learned of the decision from a senior staff member, he had a big smile on his face.