"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 by Justices Ruth Bader Ginsburg and Sonia Sotomayor.

Solicitor General Elena Kagan, who has been nominated to replace Stevens on the court, argued the case on behalf of the Obama administration and said the law has been used to prosecute about 150 cases since the Sept. 11, 2001, terrorism attacks. But it has rarely been used for the kind of speech at issue here.

The case itself predates the attacks and involves groups not often discussed in the nation's terrorism fight.

The Kurdistan Workers' Party, known as the PKK, was formed in 1974 with the aim of establishing a Kurdish state in southeastern Turkey. The Liberation Tigers of Tamil Eelam (LTTE) was founded in 1976 to try to create an independent Tamil state in Sri Lanka.

The State Department said both groups have committed terrorist attacks that have harmed Americans, and are among nearly four dozen groups designated by the government as terrorist organizations, along with more well-known ones, such as al-Qaeda, Hamas and Hezbollah.

The case was brought by several humanitarian groups, most notably the California-based Humanitarian Law Project and Ralph Fertig, a former administrative judge who is a professor at the University of Southern California.

Fertig said his goals were on behalf of peaceful goals: to train members of the PKK to use humanitarian and international law to resolve disputes; to engage in political advocacy on behalf of Turkish Kurds; and to teach PKK to petition groups such as the UN for relief.

Breyer said in his dissent that accepting the government's argument that even innocent-sounding interests could be put to use by terrorist groups "would automatically forbid the teaching of any subject in a case where national security interests conflict with the First Amendment."

But Roberts said the dissenters were demanding too much of government.

All can agree that money is "fungible," Roberts wrote; funds sent to groups for humanitarian aid could free up money that could be used for violent ends. But he said the same was true of "material support."

"It also importantly helps lend legitimacy to foreign terrorist groups -- legitimacy that makes it easier for those groups to persist, to recruit members and to raise funds -- all of which facilitate more terrorist attacks." He also said it can strain relations with allies, such as Turkey.

Roberts said the ruling was limited, and that "future applications of the material-support statute to speech or advocacy" may not survive First Amendment scrutiny.

And drawing a distinction between assisting the group and simply speaking on their behalf, he said, "We in no way suggest that a regulation of independent speech would pass constitutional muster."

He said that "under the material-support statute, plaintiffs may say anything they wish on any topic. They may speak and write freely about the PKK and LTTE, the governments of Turkey and Sri Lanka, human rights and international law. They may advocate before the United Nations." But they may not coordinate the speech with the groups on the terrorist list, he said.