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...