The Supreme Court ruled Tuesday that the government may place restrictions on protests at embassies in a decision that gives police authority to arrest demonstrators considered a "security threat."

The court, in a complex ruling with shifting majorities, held constitutional on an 8-0 vote a District of Columbia law that makes it unlawful to set up protest lines within 500 feet of a foreign embassy.However, on a 5-3 vote, the court struck down another portion of the law that prohibited the display of any sign within 500 feet of a foreign embassy if that sign tended to bring that foreign government into "public odium."

Writing for the majority, Justice Sandra Day O'Connor noted that "the need to protect diplomats is grounded in our nation's important interest in international relations."

"Doing so ensures that similar protections will be accorded those that we send abroad to represent the United States, and thus serves our national interest in protecting our own citizens," she said. "Recent history is replete with attempts, some unfortunately successful, to harass and harm our ambassadors and other diplomatic officials."

She said that because the law allows police to disperse crowds only when they believe there is a threat to the security or the peace of the embassy it is narrow enough to pass constitutional muster.

O'Connor said the law does not prohibit peaceful demonstrations. "Its reach is limited to groups posing a security threat.

"As we have noted, `Where demonstrations turn violent, they lose their protected quality as expression under the First Amendment.' "

However, O'Connor said the portion of the law prohibiting offensive signs was "inconsistent with the First Amendment" protection of freedom of speech.

Chief Justice William Rehnquist and Justice Harry Blackmun and Bryon White dissented from that portion of the ruling.

The court's newest member, Justice Anthony Kennedy, took no part in the case.

In other action, the court:

On an 8-0 vote, limited the ability of states to regulate the activities of natural gas companies. The ruling by Blackmun struck down a Michigan law requiring natural gas utilities to obtain approval from the state Public Service Commission before issuing long-term securities.

In a defeat for the Internal Revenue Service, ruled 8-0 that corporations set up to manage property on behalf of shareholders cannot be treated as separate taxpayers under the federal income tax.

The demonstration case was originally brought by four conservatives opposed to the policies of Nicaragua and the Soviet Union. They filed a lawsuit against the District of Columbia, charging the city's embassy law was unconstitutional.

The law makes it a crime to display any sign that would "bring into public odium any foreign government" within 500 feet of that country's embassy unless the demonstrators receive a permit to do so from the chief of police. The law also makes it a crime to congregate within 500 feet of an embassy.

Most notably, the law has also been used by those opposed to the policies of South Africa to gain publicity for their cause.

Police said 3,037 persons were arrested for protesting outside the South African Embassy from Thanksgiving 1984 to June 16, 1986.

Included in the arrests were such well-known people as singer Harry Belafonte, Coretta Scott King, Sen. Lowell Weicker, D-Conn., and Amy Carter, daughter of former President Jimmy Carter.

However, the law was upheld in federal court in 1984 and the appeals court agreed in August 1986.