Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

The state of Michigan will pay $87 million to replace water lines to thousands of homes in lead-contaminated Flint under a settlement agreement submitted Monday.

A hearing to approve the settlement agreement was scheduled for 1 p.m. ET Tuesday in U.S. District Court in Detroit. If Judge David Lawson OKs the deal, the Flint and Michigan governments would be obligated to dig up, inspect and replace lead or galvanized-steel water lines leading to at least 18,000 homes by Jan. 1, 2020.

The state agreed to set aside an additional $10 million for unexpected extra expenses. That's a total of $97 million the state is committing — equal to almost all of the $100 million in funds set aside for Flint earlier this month by the Environmental Protection Agency under legislation signed in December by President Barack Obama.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

There was no immediate comment from any of the parties to the suit, whom Lawson had placed under a gag order.

Flint's water crisis began as a cost-cutting measure in 2014, when the city switched its water source from Detroit's municipal service to water from the Flint River, which it treated itself. Unlike Detroit's, the Flint system didn't use chemicals to inhibit materials in the water that accelerate corrosion in lead and iron pipework — potentially exposing the city's 100,000 residents to lead and other contaminants.

In January 2015, Flint residents began taking bottles of discolored tap water to community meetings, and within a year, the city was under a state declaration of emergency. Flint returned to using Detroit's water nine months later, but the damage had already been done — a fifth of Flint water samples were found to exceed EPA lead limits in research conducted at Virginia Tech University.

Related: Bad Decisions, Broken Promises: A Timeline of the Flint Water Crisis

The National Guard began distributing bottled water and filters in Flint more than a year ago. Four state and local officials have resigned, and at least a dozen criminal cases were filed. Earlier this month, Michigan's retired director of disease control was sentenced to probation for willful neglect of duty.

Corroded water pipes at a Flint, Michigan, facility. NBC News Channel - file

The settlement was filed less than two weeks after Flint Mayor Karen Weaver met with President Donald Trump, who visited the city during the presidential campaign on Sept. 14 and promised that the crisis would "fixed quickly and effectively."

In addition to paying to rip up and replace miles and miles of old water lines, Michigan and Flint agreed to pay almost $1 million to the plaintiffs in the lawsuit, who include a Flint resident, the American Civil Liberties Union, the Natural Resources Defense Council and Concerned Pastors for Social Justice, a local activist group.

The plaintiffs agreed to drop their demand that the city deliver bottled water door to door. Instead, if the deal is approved, Flint residents will be able to call the city's 211 number and order free water for delivery within 24 hours.