A majority of Supreme Court justices seemed inclined Tuesday to accept that the federal government has the power to indefinitely hold prisoners who are deemed sexually dangerous, even if they have completed their sentences.

Solicitor General Elena Kagan told the court that, when Congress passed a law authorizing civil commitments in such cases, it was doing "something pretty simple and very reasonable." But the U.S. Court of Appeals for the 4th Circuit said Congress exceeded its authority, because the power to authorize what is normally a state function cannot be found in the Constitution.

But Kagan told the court that it is simply an extension of the federal government's recognized power "to run a responsible criminal justice system." She said that if the federal government cannot find a state willing to take responsibility for a sexually dangerous prisoner about to be released, federal officials have to step in.

Justice Ruth Bader Ginsburg seemed to agree. "You are talking about endangering the health and safety of people," Ginsburg said. "The government has some responsibility."

Others -- Justices Stephen G. Breyer and John Paul Stevens, notably -- seemed responsive to Kagan's analogy that the federal government would be within its rights to detain a soon-to-be-released prisoner who had a dangerous communicable disease.

But G. Alan DuBois, an assistant federal public defender from North Carolina, said that the federal government's power to run a criminal justice system ends when the prisoner completes his sentence and is released back into the community. If a state thinks the person poses a threat, it has the responsibility to seek a civil commitment, he said.

"The power to enforce the law which brought the defendants into federal custody in the first place has been exhausted," DuBois said. "The defendant has been tried and convicted and he's sentenced and he's served his sentence."

The law covers a small population; Kagan said the Bureau of Prisons counts only 105 such men in the category of being a danger for child molestation or sexually violent behavior. The suit that is at the court was brought by four men who have served their sentences and one who has been found incompetent to stand trial of sexually abusing a child. After the appeals court decision last spring, Chief Justice John G. Roberts Jr. agreed with the Obama administration that prisoners should not be released pending the outcome of the Supreme Court's decision.

Kagan's chief antagonist was Justice Antonin Scalia, who said, "There is no constitutional power on the part of the federal government to protect society from sexual predators." He rejected Kagan's argument that the federal government had a responsibility because the states were not taking on the task.

"This is a recipe for the federal government taking over everything," Scalia said. "The states won't do it, therefore we have to do it. It has to be done and therefore the federal government steps in and does it."

Scalia said a better -- and constitutional -- way to deal with the problem might be to make sure that a state knows a potentially dangerous person is about to be released, and set up a program to reimburse states for confining such people.

When DuBois agreed with Scalia, Stevens stepped in. He said the court must consider the case in light of a failure, which Kagan said has been documented, of states taking responsibility and whether Congress's reaction was appropriate.

"I guess we can all think of a lot of different statutes, counsel, that might be enacted," Stevens said. "We have to decide whether this one is constitutional."