WASHINGTON — The Justice Department's roundup of hundreds of illegal immigrants in the months after the Sept. 11 attacks was plagued with "significant problems" that forced many people with no connection to terrorism to languish in jails in unduly harsh conditions, an internal report released Tuesday found.

The highly critical report from the Justice Department's inspector general concluded that officials with the Federal Bureau of Investigation, particularly in New York City, "made little attempt to distinguish" between immigrants who had possible ties to terrorism and those swept up by chance in the investigation.

Justice Department officials said they acted within the law in pursuing terrorist suspects. "We make no apologies for finding every legal way possible to protect the American public from further terrorist attacks," said Barbara Comstock, a spokeswoman for the department.

But the inspector general's report found that some lawyers within the Justice Department raised concerns about the legality of the aggressive tactics, only to be overridden by senior department officials.

The report validated the concerns raised by some members of Congress and civil rights groups who charge that the Justice Department had cast too wide a net in the campaign against terrorism. The findings will likely provide both legal and political ammunition to those who have sought to curb the Justice Department's counterterrorism tactics, officials said.

Justice Department officials said that despite their disagreements with some of the report's conclusions, they have already adopted some of the 21 recommendations made by Glenn A. Fine, the department's inspector general.

Fine, appointed in 2000 by President Bill Clinton to what was regarded as a largely nonpartisan position, said that while he recognized "the enormous challenges and difficult circumstances" that the Justice Department faced after Sept. 11, "we found significant problems in the way the detainees were handled."

The inspector general, an internal watchdog, initiated the report last year, in part because of public reports of mistreatment of detainees. Most major agencies have inspector generals, who serve as independent watchdogs who periodically report on internal matters.