In the face of a lawsuit supported by both environmentalists and chemical manufacturers, the federal government agreed yesterday to establish a special agency to study the health effects of toxic chemicals.

Under terms of a consent decree filed in U.S. District Court here, the Health and Human Services Department will establish an Agency for Toxic Substances and Disease Registry, as mandated by Congress in the 1980 "Superfund" hazardous waste cleanup law.

The Environmental Defense Fund filed suit in February, contending that the special unit was essential to proving a link between chemical exposure and long-term health problems. The suit also was supported by the Chemical Manufacturers Association, which believed the data was needed to disprove such a link. HHS had declined to establish the agency on grounds that the Reagan administration was seeking legislation to rescind the requirement.

Ellen Silbergeld, a scientist with the environmental group, called the consent decree "a victory for all of us" but complained that "we had to sue HHS to get what anyone can understand is the minimum requirement for good policy, that is, adequate collection of data."

The new agency, which will operate under the Centers for Disease Control, will maintain a list of all persons exposed to toxic substances, as well as contaminated sites. It also will help provide medical care and testing to persons exposed to toxic materials in emergencies, such as train derailments, and will conduct screening programs to determine relationships between exposure and illness.