The US supreme court has upheld a broad-ranging law that allows Americans who offer advice to banned organisations, including legal assistance and information on conflict resolution, to be prosecuted as terrorists.

The case arose out of human rights advice given by a California group to Kurdish and Tamil organisations that are listed as terrorist groups in the US.

The supreme court upheld the Obama administration's argument that even advice intended to be used for peaceful purposes amounted to "material support" for terrorism.

That includes a lawyer submitting a friend-of-the-court brief on behalf of a banned group or helping a proscribed organisation to petition international bodies to bring an end to a violent conflict.

"The supreme court has ruled that human rights advocates, providing training and assistance in the nonviolent resolution of disputes, can be prosecuted as terrorists," said David Cole, a Georgetown university law professor who argued the case before the court.

"In the name of fighting terrorism, the court has said that the first amendment [on free speech] permits congress to make it a crime to work for peace and human rights. That is wrong."

The ruling is likely to further complicate the work of activists in support of controversial causes that has already seen highly contentious prosecutions over other forms of support, such as fundraising.

Palestinian activists have been prosecuted and jailed for raising cash for social groups dealing with issues such as housing and welfare that have ties to Hamas, which governs Gaza.

Individuals and groups offering legal or other specialist advice to such groups are also now open to prosecution.

The ruling involved the Humanitarian Law Project in Los Angeles, which provided human rights training to the Kurdistan Workers' Party (PKK).

It argued that the assistance was nonviolent and did not promote the goals of the PKK.

One of the plaintiffs, Ralph Fertig, is a retired lawyer who had sought to help the PKK bring attention to the rights of Kurds at international bodies.

The US government said it regarded that as support for terrorism. It argued that Fertig was free to speak in support of the PKK's aims but that he could not provide it with advice.

The Kurdistan Workers' Party is one of about 30 organisations listed as terrorist organisations by the US government. The others include Hamas, Hezbollah and the Khmer Rouge.

A lower court had struck down the law as unconditionally vague.

But by a majority of 6-3, the supreme court ruled that the government has the right "to prohibit providing material support in the form of training, expert advice, personnel, and services to foreign terrorist groups, even if the supporters meant to promote only the groups' non-violent ends".

The chief justice, John Roberts, said: "At bottom, plaintiffs simply disagree with the considered judgment of congress and the executive that providing material support to a designated foreign terrorist organisation – even seemingly benign support – bolsters the terrorist activities of that organisation."

The dissenting judges said that the decision "deprives the individuals before us of the protection the first amendment demands".

In hearing the case, the justices discussed what amounts to specialist advice and whether it is a crime to teach a terrorist to play the harmonica.

The government's case was argued in February by Elena Kagan, who is now the Obama administration's nominee to the supreme court.

"Hezbollah builds bombs. Hezbollah also builds homes. What Congress decided was when you help Hezbollah build homes, you are also helping Hezbollah build bombs. That's the entire theory behind the statute," she told the court.