WASHINGTON—The Supreme Court upheld a federal law banning "material support" for foreign terrorist organizations, even advice about entirely legal activities, disregarding arguments that the measure treads on free speech rights.

The vote was 6-3, with Chief Justice John Roberts writing for the majority. Justice Stephen Breyer dissented, joined by two other liberals.

Although...