The Justice Department has reached a $38.5 million settlement with the Velsicol Chemical Corp. of Chicago that will require the company to pay for the cleanup of three hazardous waste sites in Michigan.

The agreement comes after a lengthy investigation touched off by the discovery that poisonous polybrominated biphenyls (PBBs) produced by Velsicol were mistakenly mixed with cattle feed in 1973, forcing the slaughter of 10,000 cattle and causing farmers to lose millions of dollars.

Velsicol will pay $24.5 million to clean up three hazardous waste sites in south-central Michigan and $14 million to reimburse the federal and state governments.

Carol E. Dinkins, assistant attorney general in charge of the lands and natural resources division, yesterday said the settlement was the largest ever in a hazardous waste enforcement case.

Chemicals, including the banned insecticide DDT, the fire retardants PBB and Tris, benzene and carbon tetrachloride, have been found in the Gratiot County Landfill and at the site of a now-closed plant that belonged to Michigan Chemical Corp., Velsicol's predecessor, in St. Louis, Mich., about 45 miles north of Lansing. The plant was in operation from 1936 to 1978.

The investigation found that in addition to the plant site and the landfill, a nearby golf course also was contaminated by chemical seepage.

PBBs, a flame retardant made by Velsicol until 1974, were mistakenly mixed with cattle feed and eventually entered the food chain and caused illness and possibly cancer in Michigan residents. Velsicol was not held responsible in subsequent court suits.

The agreement among Velsicol, the state of Michigan, the Justice Department and Environmental Protection Agency calls for the company to pay damages to the state and to pay for the cleanup, which will be supervised by the state Department of Natural Resources. Velsicol is required to complete all work by Nov. 15, 1984.

The settlement provides that Velsicol will:

* Pay Michigan $13.5 million for the cost of cleanups and investigations.

* Pay $500,000 to the EPA for the cost of investigations.

* Provide an estimated $14.5 million in materials and services for cleaning up both the landfill and the golf course.

* Pay an estimated $10 million to clean up the closed St. Louis plant. Contaminated earth from all three sites will be buried at the former plant site under a 50-acre impermeable clay cap and surrounded by 21-inch-thick containment walls.

* Velsicol will be required to erect a fence around the site, with signs saying: "Warning--Toxic Chemical Burial Area--KEEP OUT."