WASHINGTON—The Supreme Court affirmed President Donald Trump’s power to block citizens of several Muslim-majority nations from entering the U.S., a 5-4 decision on Tuesday that lifted legal hurdles on a central initiative of the Trump presidency but is unlikely to end the bitter politics that surround it.

In an opinion by Chief Justice John Roberts, the court’s conservative majority lined up behind a president’s power to suspend legal entry under a federal law that, they wrote, “exudes deference to the president in every clause.”

Contrasting with two earlier versions of the travel ban that floundered in the courts, the proclamation Mr. Trump signed last September easily meets legal standards, the court wrote, because the administration provided more detail and justification than in prior instances when presidents from Jimmy Carter to Barack Obama exercised their authority to suspend the entry of certain aliens.

All four liberal justices wrote that they would have struck down the travel ban, castigating the majority for ignoring the religious bias they believe animated a policy that traces from Mr. Trump’s campaign promise to impose “a total and complete shutdown of Muslims’ entering” the U.S.

Two of the dissenters, Justices Sonia Sotomayor and Ruth Bader Ginsburg, called the ruling one of the most troubling in recent memory. “History will not look kindly on the court’s misguided decision today, nor should it,” Justice Sotomayor said from the bench.