The government went too far in trying to ban computer simulations and other fool-the-eye depictions of teenagers or children having sex, the Supreme Court ruled Tuesday.

Youthful sexuality is an old theme in art, from Shakespeare to Academy Award-winning movies, the court found in striking down key provisions of a 1996 child pornography law on free speech grounds.

The law would call into question legitimate educational, scientific or artistic depictions of youthful sex, Justice Anthony M. Kennedy wrote for a 6-3 majority.

"The statute proscribes the visual depiction of an idea — that of teenagers engaging in sexual activity — that is a fact of modern society and has been a theme in art and literature throughout the ages," Kennedy wrote in a decision joined by four other justices. Clarence Thomas, one of the court's most conservative justices, wrote a separate opinion agreeing with the outcome.

The court invalidated two provisions of the Child Pornography Prevention Act as overly broad and unconstitutional. Free speech advocates and pornographers had challenged the law's ban on material that "appears to be" a child in a sexually explicit situation or that is advertised to convey the impression that someone under 18 is involved.

Attorney General John Ashcroft said the ruling makes prosecution of child pornographers "immeasurably more difficult." He offered to work with Congress on new legislation that could withstand the court's scrutiny.

It is not clear how many people have been prosecuted under the stricken provisions, nor what might become of convictions. Ashcroft said prosecutors will retool some indictments to rely on obscenity law that was unaffected by Tuesday's ruling.

Another section of the 1996 law was not challenged, and remains in force. It bans prurient computer alteration of innocent images of children, such as the grafting of a child's school picture onto a naked body.

Justices John Paul Stevens, David H. Souter, Ruth Bader Ginsburg and Stephen G. Breyer signed Kennedy's opinion. Thomas, in a separate concurring opinion, said the court's ruling appropriately strikes down a ban that was too sweeping but leaves a window for future regulation of some kinds of virtual child pornography.

Justice Sandra Day O'Connor partially agreed with the majority and partially disagreed. The law is indeed too broad, but a portion of it could be salvaged, O'Connor wrote.

Chief Justice William H. Rehnquist and Justice Antonin Scalia dissented, arguing that the law need not be read to ban the kind of artistic material that concerned Kennedy.

"The aim of ensuring the enforceability of our nation's child pornography laws is a compelling one," Rehnquist wrote for the pair. "The (law) is targeted to this aim by extending the definition of child pornography to reach computer-generated images that are virtually indistinguishable from real children engaged in sexually explicit conduct."

Conservatives outside the court were outraged.

"That the Supreme Court of the United States can entertain the notion that virtual images of children being sexually violated has 'value' that needs protection is an abomination," said Jan LaRue, legal studies director at the Family Research Council.

"The high court sided with pedophiles over children," said Rep. Mark Foley, R-Fla., co-chair of a congressional caucus on missing and exploited children. "This decision has set back years of work on behalf of the most innocent of Americans."

Congress passed the law as a bulwark against then-emerging computer technology that allowed pornographers to simulate child sex without using actual children.

The law was intended primarily to stop pornography produced through computer wizardry not available when the court placed child pornography outside First Amendment protection in 1982.

But moviemakers and other artists complained that the law also swept up scenes such as those in works Kennedy named, where youthful sex is pantomimed or is filmed using adults disguised as children.

"Teenage sexual activity and the sexual abuse of children have inspired countless literary works. William Shakespeare created the most famous pair of teenage lovers, one of whom is just 13," Kennedy wrote, referring to Romeo and Juliet.

"In the drama, Shakespeare portrays the relationship as something splendid and innocent," yet modern staging of the play could run afoul of the anti-child pornography law, Kennedy suggested.

In Hollywood, the Directors Guild of America praised the decision. "From Romeo and Juliet to American Beauty and Traffic, artists have told stories that included allusions of adolescent sexuality, stories which have enriched our lives," said DGA president Martha Coolidge.

Coolidge, whose films include the teen comedies Valley Girl and Real Genius, said, "Every American would suffer the loss of freedom if this overzealous governmental intrusion into our rights of expression had been allowed to stand."

The case is Ashcroft v. Free Speech Coalition, 00-795.