The Supreme Court engaged in a lively discussion of state sodomy laws yesterday, hearing a challenge to a Texas statute that prohibits "deviate sexual intercourse" between people of the same sex but does not apply to heterosexual activity.

Paul M. Smith, the lawyer for two Texas men who were discovered by police having anal intercourse in a Houston apartment, told the court that the law was an unconstitutional invasion of privacy rights and violated the equal protection clause of the 14th Amendment because "it is directed not just at conduct but at a particular group of people -- same-sex couples."

But Harris County, Tex., District Attorney Charles A. Rosenthal Jr. retorted that there is a long tradition in the country of regulating sexual activity outside of marriage, and that Texas "has a right to set moral standards and can set bright line moral standards for its people."

The justices appeared divided during the spirited oral arguments. Chief Justice William H. Rehnquist and Justice Antonin Scalia expressed sympathy for the state's position, while Justices David H. Souter, Ruth Bader Ginsburg and Stephen G. Breyer peppered Rosenthal with skeptical questions about the Texas law.

The case has worked its way through the entire U.S. judicial system, beginning in a Harris County Justice of the Peace court, to a county criminal court, a state district appeals court and the Texas Court of Criminal Appeals before it finally reached the nation's highest court. It began on Sept. 17, 1998, when a false report of a disturbance involving a gun led police to enter the home of John G. Lawrence, where he was discovered having anal sex with Tyron Garner.

The two men were convicted of violating the Texas Homosexual Conduct law and were fined $200 each. The convictions were reversed at one stage in the appeals process but were eventually reinstated and upheld by the Texas Court of Criminal Appeals, the state's highest criminal court.

In accepting the case, the Supreme Court confronted one of its own precedents, a 1986 ruling that upheld a Georgia sodomy law. In that case, a narrow majority said that the right of privacy did not extend to "morally reprehensible" activities such as sodomy. Smith, the lawyer for the two Texas men, explicitly asked the court yesterday to overturn its 1986 ruling.

Since the early 1960s, when all states had sodomy laws, the number of such laws has diminished Currently, Texas and three other states -- Kansas, Missouri and Oklahoma -- have laws banning sodomy between people of the same sex. Nine other states, including Virginia, have sodomy laws that apply to same-sex couples and heterosexuals.

The case has attracted widespread attention and a flurry of briefs by outside groups supporting one side or the other. The emotional nature of the dispute was also on display outside the stately court building yesterday as a group of anti-gay rights demonstrators held signs denouncing homosexuality. A young girl held aloft a sign that said "Thank God for Sept. 11," an apparent reference to statements by conservative Christian leaders Jerry Falwell and Pat Robertson that the 2001 terrorist attacks reflected God's anger at gay rights and abortion rights supporters.

Inside the building, Scalia, the most outspoken of the court's conservative justices, challenged Smith's assertion that the Texas law's application to only same-sex couples violated equal protection provisions of the Constitution. He said many laws make such distinctions.

"Aren't there statutes on adultery?" Scalia said. "Are they unconstitutional? What about rape laws that only apply to male-female rape? Do you think they're unconstitutional?"

Rehnquist added that "almost all laws are based on approval of some people or conduct. That's why people legislate."

Smith replied that to impose a limitation on one group there has to be a justification and that the justification for the Texas law was "irrational."

"The state has to have a greater justification than that we prefer to push people toward heterosexuality," he said.

Rosenthal received equally skeptical treatment. He argued that in prohibiting certain types of sexual activity, "our position is the line should be drawn at the marital bedroom door, through which law enforcement can't pass."

"This case is in the bedroom," Breyer shot back.

Asked by Justice John Paul Stevens about a Supreme Court ruling that overturned a Virginia law that banned interracial marriage, Rosenthal said that law "violated a fundamental right."

"That's the issue here," Stevens said.

Breyer said the "hard question" was whether states can enact laws based on what lawmakers believe is immoral. Rosenthal said such laws would "have to have a rational basis," and Breyer replied, "You haven't given us a rational basis except to say it's immoral."

Rosenthal also argued that when states have changed their laws regarding sodomy, they "have done it through the legislative process. That's where we think this belongs, in the statehouse of Texas."

There were moments of comic relief. After Scalia suggested that the Texas sodomy law was part of a "200-year tradition" and therefore should be presumed constitutional, Rosenthal acknowledged in response to a question from Souter that he doubted that Texas was even a state in 1803. (Texas became a state in 1845.) "That's a trick question," Scalia interjected.

The case, which the court is expected to decide by early summer, is Lawrence v. Texas No. 02-102.

Defense lawyers Ruth Harlow and Paul Smith talk to reporters. Harris County prosecutor Charles A. Rosenthal Jr. after arguments.