A federal appeals court ruled yesterday that Congress violated the Constitution by picking sides in one of Washington's most contentious custody battles and by passing a 1996 law that singled out the father for punishment and scorn.

The mother, Washington area plastic surgeon Elizabeth Morgan, drew international attention by waging an epic battle to keep her ex-husband, Eric A. Foretich, away from their daughter. The dispute dates to 1985, when Morgan first accused Foretich of sexually abusing their daughter, who was not yet 3. Foretich denied the allegation, and a judge hearing the custody dispute ruled that Morgan failed to prove it.

Morgan eventually spent 25 months in jail because she refused to comply with a court order giving Foretich visitation rights and refused to say where the girl was. She was released in 1989 and joined her daughter in New Zealand.

The appellate ruling stemmed from an act of Congress, passed in September 1996, that cleared the way for Morgan and the girl to return home without coming under the court's oversight. Rep. Frank R. Wolf (R-Va.) helped attach the legislation to a massive transportation spending bill. The measure did not mention Morgan or Foretich by name, but its language was written so narrowly that it applied only to their case. It shielded Morgan from D.C. court orders and contempt citations and barred Foretich from visiting their daughter without the child's express consent. Morgan and her daughter returned to the United States in 1997.

Foretich and his parents challenged the legislation in a lawsuit filed in 1997. Last year, a federal judge sided with Morgan and Congress. But yesterday, a three-judge panel of the U.S. Court of Appeals for the D.C. Circuit handed Foretich an overwhelming symbolic victory and chastised Congress for overstepping its bounds.

The panel ruled unanimously that the "Elizabeth Morgan Act" unfairly harmed Foretich's reputation by treating him as a danger to his child without facts or formal charges.

"Despite a feeble attempt at generality, there is no doubt that Congress targeted Dr. Foretich," Judge Harry T. Edwards wrote for the panel. By suggesting Foretich would harm his daughter, Congress "inflicted extraordinary reputational injuries" on Foretich and illegally punished him, he wrote.

The ruling has no effect on the core issue of the court fight. The couple's daughter, who once was named Hilary and now goes by the name of Ellen Morgan, is 21 and no longer subject to rulings in the custody case. Reached yesterday at her mother's home in Northwest Washington, Ellen Morgan declined to comment.

Foretich, an oral surgeon who practices in McLean, said in a telephone interview yesterday that he was "so very grateful" for the court's decision that he was near tears when his attorney relayed the news as he finished a morning surgery.

"I feel like someone just gave me back my good name," said Foretich, 61, who lives in Great Falls. "It's not going to bring my daughter back. It's not going to redress and bring back all the lost years, all the pain, heartache. But it restores my faith in our system of government."

Foretich said he has not spoken to his daughter since she was 4, and has given up trying to contact her. He said he would like to have a relationship with her, "but frankly, that will have to come from her."

Foretich said he hopes Wolf "takes a good hard look at himself in the mirror tomorrow morning and realizes what he did to me."

Elizabeth Morgan, 55, did not return calls to her office and home, and her attorney declined to comment.

Wolf also declined to comment.

Yesterday's decision reverses the ruling of Senior Judge William B. Bryant of U.S. District Court in Washington. The appellate panel said that being able to play a role in the upbringing of one's child is a fundamental right and cannot be infringed without a strong reason. Edwards was joined in the ruling by Judges A. Raymond Randolph and David S. Tatel.

Tatel also wrote that the government's argument that Congress intended to protect a minor fell short because lawmakers could have imposed less restrictive safeguards, such as barring Foretich from unsupervised visits.

The judges declared that the law was a "bill of attainder," violating the Constitution because it punished a person or small group.

Foretich's attorney, Jonathan Turley, called the ruling "a long-awaited vindication for the Foretich family, who have weathered an extremely long storm in trying to protect their family name."

The Morgan-Foretich battle attracted extraordinary publicity and inspired books and movies. Morgan became a cause celebre for mothers fighting domestic abuse. Wolf first stepped in to help her in 1989 when he helped push through a law that allowed Morgan to be freed from jail.

Elizabeth Morgan and daughter Ellen, in a 1996 photo, returned to the United States from New Zealand after Congress passed a law shielding Morgan from court orders in the custody battle with her ex-husband.