A federal law that bans on-the-job sexual harassment can apply even when the harasser and victim are the same sex, the Supreme Court ruled Wednesday in a case of enormous importance for American workplaces.

In a case closely watched by gay rights groups, the decision provides victims of homosexual harassment with their first-ever federal remedy.By a unanimous vote, the court revived the federal lawsuit of a Louisiana man who says he was sexually pursued and harassed by his male supervisor and two other men during his four months working on a Gulf of Mexico oil rig.

But the court made clear that someone claiming same-sex harassment must prove that the alleged discrimination was based on gender and "not merely tinged with offensive sexual connotations."

There was no specific mention in the decision about harassment based on sexual orientation, however. Congress has never outlawed such bias.

The ruling nevertheless was hailed by gay-rights advocates.

"This is a victory for all American workers. We're pleased that the court understands that sexual harassment is about power and that sexual orientations of the people involved are irrelevant," said Kim Mills of the Human Rights Campaign.

Beatrice Dohrn of the Lambda Legal Defense and Educational Fund added: "Had the court carved out an exception for same-sex claims, that would have had a great negative implication for gay rights."

The court said same-sex harassment can violate an anti-bias law known as Title VII of the Civil Rights Act of 1964.

"We see no justification . . . for a categorical rule excluding same-sex harassment claims from the coverage of Title VII," Justice Antonin Scalia wrote for the court.

His relatively brief, seven-page opinion offered new guidelines for judges nationwide.

The law "does not reach genuine but innocuous differences in the ways men and women routinely interact with members of the same sex and of the opposite sex," Scalia wrote. "The prohibition of harassment on the basis of sex . . . forbids only behavior so objectively offensive as to alter the conditions of the victim's employment.

"Conduct that is not severe or pervasive enough to create an objectively hostile or abusive work environment - an environment that a reasonable person would find hostile or abusive - is beyond Title VII's purview."

The term "harassment" does not appear in the text of Title VII, but the Supreme Court ruled in 1986 that harassment amounts to discrimination if it creates a "hostile environment" in the work-place.

In subsequent rulings, the justices said a hostile environment can come about not only by overtly sexual behavior but also by "discriminatory intimidation, ridicule and insult . . . sufficiently severe or pervasive to alter the conditions of the victim's employment."

A federal appeals court ruled that the federal law never applies to same-sex harassment, but when Joseph Oncale's case was argued before the nation's highest court in December it appeared clear the appeals court would be reversed.

"I don't see how we could possibly sustain the ruling," Chief Justice William H. Rehnquist said back then.

Oncale's lawsuit stems from his four months of work in 1991 as a roustabout assigned to a Gulf of Mexico oil rig with Sundowner Offshore Services.

His lawsuit against Sundowner and three men said he was sexually assaulted, battered, touched and threatened with rape by his direct supervisor, John Lyons, and a second supervisor, Danny Pippen. Another defendant, coworker Bran-don Johnson, was accused of assisting in one of the alleged incidents.

Oncale, who now lives in a small town near Baton Rouge, said he twice reported the situation to his employer's highest-ranking representative on the job site, but no action was taken. He said he quit because he feared the harassment would escalate to rape.

All three men named as defendants say no illegal harassment occurred, and portray their conduct as hazing or locker-room horse-play.

A national group of employers, the Equal Employment Advisory Council, told the justices that allowing same-sex harassment lawsuits under the federal law would convert it "into an unmanageably broad code of working behavior."

In Wednesday's decision, Scalia said concerns that Title VII will become "a general civility code for the American workplace" are misguided.