Officials say National Grid has agreed to pay $5.38 million to state and federal agencies to resolve claims over environmental damage caused by the defunct Gloucester Gas Light Company. The plant operated from 1854 to 1952. Officials said Friday that hazardous chemicals released by the plant contaminated soil, groundwater and sediment in Gloucester Harbor. The company used a chemical process to transform coal and oil into gas, yielding tar, sludge and oil as byproducts. Ownership has changed twice since the plant closed. National Grid is the current owner.