WASHINGTON – The Supreme Court on Monday upheld a federal law that forbids providing training and advice to terrorist organizations even about entirely peaceful and legal activities, saying it does not violate the free speech rights of those who want to help.

The court ruled 6-3 that Congress and the executive branch had legitimate reasons for barring “material support” to foreign organizations deemed to be terrorists in the USA Patriot Act.

Those challenging the law “simply disagree with the considered judgment of Congress and the executive that providing material support to a designated foreign terrorist organization – even seemingly benign support – bolsters the terrorist activities of that organization,” Chief Justice John Roberts wrote for the majority.

“That judgment, however, is entitled to significant weight, and we have persuasive evidence before us to sustain it.”

He was joined by the court’s conservatives – Justices Antonin Scalia, Anthony Kennedy, Clarence Thomas and Samuel Alito – as well as its most liberal member, retiring Justice John Paul Stevens.

Justice Stephen Breyer took the relatively unusual step of reading his dissent from the bench, saying the court had abandoned its role of protecting individual liberties under the First Amendment because of national security threats Congress did not adequately justify.

“In such cases, our decisions must reflect the Constitution’s grant of foreign affairs and defense powers to the president and to Congress but without denying our own special judicial obligation to protect the constitutional rights of individuals,” Breyer said.

“That means that national security does not always win.”

He was joined in the dissent by Justices Ruth Bader Ginsburg and Sonia Sotomayor.

Human rights groups said they were stunned by the ruling.

David Cole, a Georgetown law professor who represented the aid groups at the Supreme Court, said the court essentially ruled that “the First Amendment permits the government to make human rights advocacy and peacemaking a crime.”

The Obama administration said the law has been used about 150 times since the Sept. 11, 2001, terrorism attacks. But it has rarely been used for the kind of speech involved in this case.

The aid groups that challenged the law had trained a Kurdish group in Turkey on how to bring human rights complaints to the United Nations and assisted them in peace negotiations.

They suspended the activities when the U.S. designated the Kurdish organization, known as the PKK, a terrorist group in 1997. The groups wanted to give similar help to a group in Sri Lanka, but it also was designated a terrorist organization by the U.S. in 1997.

Nearly 48 organizations are on the State Department list, including al-Qaida and Hamas.

The humanitarian groups, including the California-based Humanitarian Law Project; Ralph Fertig, a civil rights lawyer; and Nagalingam Jeyalingam, a physician, want to offer assistance to the Kurdistan Workers’ Party in Turkey or the Liberation Tigers of Tamil Eelam in Sri Lanka.

The government says the PKK has been involved in a violent insurgency that has claimed 22,000 lives. The Tamil Tigers waged a civil war for more than 30 years before their defeat last year.

Both foreign organizations are “deadly groups,” Roberts wrote, that have caused harm to Americans.

It is easy to see how money is “fungible,” Roberts wrote; funds used for humanitarian aid to the groups could free up money that could be used for violent ends.

But he said the same was true of “material support.”