President Bush has the legal power to order the indefinite military detentions of civilians captured in the United States, the federal appeals court in Richmond, Va., ruled on Tuesday in a fractured 5-to-4 decision.

But a second, overlapping 5-to-4 majority of the court, the United States Court of Appeals for the Fourth Circuit, ruled that Ali al-Marri, a citizen of Qatar now in military custody in Charleston, S.C., must be given an additional opportunity to challenge his detention in federal court there. An earlier court proceeding, in which the government had presented only a sworn statement from a defense intelligence official, was inadequate, the second majority ruled.

The decision was a victory for the Bush administration, which had maintained that a 2001 Congressional authorization to use military force after the Sept. 11 attacks granted the president the power to detain people living in the United States.

The court effectively reversed a divided three-judge panel of its own members, which ruled last year that the government lacked the power to detain civilians legally in the United States as enemy combatants. That panel ordered the government either to charge Mr. Marri or to release him. The case is likely to reach the Supreme Court.