Northport Village will receive $5 million in state funding for the final phase of a massive multiyear upgrade to its wastewater treatment system, state and local officials said.

The money will allow the village to replace two sections of old, fragile sewer lines with new pipe to be buried beneath the village’s shoreline.

“These funds will help Northport make the necessary improvements that are long overdue,” Mayor George Doll said in a news release Thursday.

The two cast-iron, Depression-era pipelines currently run beneath Woodbine Avenue and along the Northport Harbor bed.

The pipes are significantly deteriorated, long past their intended life span and “in danger of serious failure,” Village trustee Damon McMullen said earlier this year.

Both lines will be replaced with one more durable pipeline made of high-density polyethylene.

advertisement | advertise on newsday

The line also will have greater capacity: The old lines are 8 inches in diameter, while the new one will be at least 12 inches in diameter, officials have said.

The greater size also will make it possible to eventually move more Northport residents onto village sewer lines and off cesspools, which can leach nitrogen and other contaminants into the groundwater.

The grant money came from the New York State and Municipal Facilities Program. The village will be reimbursed as it incurs expenses, said a spokesman for state Sen. John J. Flanagan (R-East Northport), who along with Sen. Carl L. Marcellino (R-Syosset) secured the funding for the village.

“Sewers are the hidden impediment to economic revitalization and crucial to protecting our environment,” Marcellino said in a statement. “A break in this system would have resulted in roadway destabilization and runoff into Northport Harbor and the Long Island Sound.”

The cost of the pipeline replacement, originally expected to be $4 million, went up by $1 million after preliminary work revealed underground complications, according to Flanagan’s office.

The U.S. Environmental Protection Agency cited Northport in 2011 for failing to have plans in place to manage storm water and other discharges into Northport Harbor.

Since then, Northport has upgraded its sewage-treatment plant, relined sewer mains and rehabilitated manhole covers — all of which helped the village meet a mandate that it reduce the plant’s nitrogen emissions from 18.5 pounds per day to 10 pounds or less per day.

Plant emissions vary depending on temperatures and other environmental factors, but officials have said that it consistently averages below 10 pounds per day through improvements made during the project’s first two phases.