The state of Michigan has agreed to fund the replacement of thousands of lead-tainted water lines to settle a lawsuit filed by Flint residents and an environmental group last year.

Michigan will be paying $87 million to replace more than 18,000 galvanised-steel water lines by 2020 in the struggling city, the Associated Press reports. The 92-page settlement will be presented to a judge for his approval on Tuesday morning.

Under the agreement, the state will still provide free bottled water distribution centres and delivery services for Flint residents. Officials will also set aside another $10 million in case more pipes need replaced.

In pictures: Flint water crisis Show all 10 1 /10 In pictures: Flint water crisis In pictures: Flint water crisis Anthony Fordham picks up bottled water from the Food Bank of Eastern Michigan to deliver to a school after elevated lead levels were found in the city's water in Flint Reuters In pictures: Flint water crisis Michigan National Guard Staff Sergeant William Phillips (L) assists a Flint resident with bottled water at a fire station in Flint Reuters In pictures: Flint water crisis Flint residents Arthur Woodson, left, and Tony Palladino Jr. protest the arrival of Flint native and filmmaker Michael Moore as Moore accuses Gov.Rick Snyder of poisoning Flint water during a rally outside of city hall in Flint AP In pictures: Flint water crisis Flint residents pick up bottled water and water filters at a fire station in Flint. Michigan National Guard members were set to arrive in Flint to join door-to-door efforts to distribute bottled water and other supplies to residents coping with the city's crisis over lead-contaminated drinking water Reuters In pictures: Flint water crisis Soldiers from the Michigan Army National Guard Flint prepare to give Flint residents bottled water at a fire station in Flint Getty Images In pictures: Flint water crisis Justin Roberson (L), age 6, of Flint, Michigan and Mychal Adams, age 1, of Flint wait on a stack of bottled water at a rally where the Rev. Jesse Jackson was speaking about about the water crises at the Heavenly Host Baptist Church in Flint Getty Images In pictures: Flint water crisis A man sits next to a stack of bottled water at the Heavenly Host Baptist Church in Flint 2016 Getty Images In pictures: Flint water crisis The top of a water tower is seen at the Flint Water Plant. President Barack Obama declared a state of emergency in Michigan and ordered federal aid to be used to help state and local response efforts to an area affected by contaminated water Reuters In pictures: Flint water crisis Rosie Wright, center, rallies with the crowd over Flint's water crisis in Ann Arbor, Michigan AP In pictures: Flint water crisis Rick Catherman participates in a rally around Flint's water crisis in Ann Arbor, Michigan AP

The man-made water crisis began in 2014 when city officials swapped the water supply from the Detroit River to the Flint River. Lead soon began contaminating the city’s water source. Authorities also failed to treat the corrosion.

“The proposed agreement is a win for the people of Flint,” Dimple Chaudhary, an attorney with the Natural Resources Defense Council, which represents Flint citizens, told the AP. “It provides a comprehensive framework to address lead in Flint tap water and covers a number of critical issues related to water safety.”

In January of this year, the water quality in Flint improved to federal standards but officials still warned residents not to drink the water, deeming it unsafe because the pipes still needed to be replaced.