The issue arose in a program intended to fight HIV and AIDS overseas. In order to receive funding, foreign aid groups were required by a 2003 law to adopt a policy explicitly opposing prostitution and sex trafficking. Nonprofit groups active in fighting disease contended the requirement violated their First Amendment free-speech rights.

Writing for a 6-2 court, Chief Justice
John Roberts
agreed. While the justices previously have held that in some circumstances the government can limit grantees' speech when conducting publicly funded activities, forcing recipients to espouse official views goes too far, the court found.

The aid groups said they didn't advocate prostitution or sex-trafficking, but that their work might be impeded if they were required to take positions that are controversial in the disease-prevention field or might alienate prostitutes and others whom they are trying to reach.

"Public health groups cannot tell sex workers that we 'oppose' them, yet expect them to be partners in preventing HIV," said Marine Buissonniere, director of the Open Society Public Health Program, one of the groups involved in the challenge.

The U.S. Agency for International Development, which administers the program, didn't have an immediate comment.

The 2003 U.S. law made billions of dollars available to fight the transmission of deadly diseases in the developing world, in large part through private nonprofit groups and international organizations.

Congress found that the sex industry contributed to the spread of disease and declared it U.S. policy to eradicate prostitution and "other sexual victimization."

The act barred using U.S. funds to promote prostitution. Aid groups didn't challenge that provision, but sued to block a companion rule requiring them to "have a policy explicitly opposing prostitution and sex trafficking."

The Obama administration argued the challenged rule was no different than a restriction on domestic family-planning programs the court upheld in 1991.

In that case, the justices upheld a Reagan administration regulation that, among other provisions, forbade participating doctors from counseling patients about abortion or referring them to abortion providers. Since the family-planning program didn't include abortions, the restrictions were "designed to ensure that the limits of the federal program are observed," the court found then.

The two justices who remain from the 1991 case—both of whom joined then-Chief Justice William Rehnquist's majority opinion—split on the precedent's meaning. Justice
Anthony Kennedy
joined Chief Justice Roberts on Thursday, while Justice
Antonin Scalia
dissented.

Chief Justice Roberts wrote that "as a general matter, if a party objects to a condition on the receipt of federal funding, its recourse is to decline the funds." He observed that the court has upheld other speech-related funding conditions, including a requirement that law schools permit military recruiting or jeopardize government grants to their parent university.

But there is a limit, the chief justice said. In Thursday's case, Congress went "beyond defining the limits of the federally funded program to defining the recipient," he wrote. "It is about compelling a grant recipient to adopt a particular belief as a condition of funding."

In dissent, Justice Scalia, joined by Justice
Clarence Thomas,
said the condition was "nothing more than a means of selecting suitable agents to implement the Government's chosen strategy to eradicate HIV/AIDS."

In his ruling, the chief justice enlisted one of the court's most celebrated precedents, the 1943 decision holding it unconstitutional to force schoolchildren to recite the Pledge of Allegiance.

"We cannot improve upon what Justice [Robert] Jackson wrote for the Court 70 years ago: 'If there is any fixed star in our constitutional constellation, it is that no official, high or petty, can prescribe what shall be orthodox in politics, nationalism, religion, or other matters of opinion,'" the chief justice wrote, joined by Justices Kennedy,
Ruth Bader Ginsburg,
Stephen Breyer,
Samuel Alito and Sonia Sotomayor. Justice Elena Kagan, who was solicitor general at earlier stages of the litigation, sat out.