WASHINGTON, July 2 — Seeking a legal path to shutting down the Guantánamo detention facility, senior advisers to President Bush are exploring whether the White House and Congress can agree to legislation that would permit the long-term detention of foreign terrorism suspects on American soil, Pentagon and administration officials say.

The idea of creating a new legal category for some foreign terrorism detainees, which is still in its early stages, faces daunting political, legal and constitutional difficulties. But it is gaining support among some White House and national security officials as the most promising course to allow the president to close the site at Guantánamo Bay, Cuba, that has generated intense criticism at home and abroad.

Essentially, the administration would propose legislation that would result in dividing the estimated 375 Guantánamo detainees into three legal categories. The one that would call for legislative action would include detainees like Khalid Shaikh Mohammed, the mastermind of the September 2001 attacks, and others whose trials would risk exposing intelligence operations. This group, estimated at two dozen to 50, would be placed indefinitely in military brigs on American soil.

A second group would also be moved to the United States, most likely to face trial in military courts, but perhaps with more legal guarantees than in the current military tribunal system.