In a judgement released on March 20, Judge Jeff Smith ruled in favour of the regional council, granting a series of enforcement orders under the Resource Management Act.
Among other things, he ordered the district council to pass a resolution by April 5 approving funding for an upgrade and to complete a final design by July 26.
Work had to start by August 2 and the upgrade had to be finished by May 25, 2020.
Any failure to follow those orders would see the matter return to court, Judge Smith said.
He also instructed the district council to pay the regional council's costs and come up with a way to reduce ammonia levels while the upgraded plant was being built.
On April 4, a day before the court-ordered deadline, the district council called an extraordinary meeting which was closed to the public. The meeting agenda shows the items discussed were the Manea Footprints of Kupe Centre in Opononi and Paihia's wastewater treatment plant.
In a written response to the Advocate, infrastructure manager Andy Finch said $3.3 million had already been dedicated to upgrading the plant in the 2018-19 Long Term Plan. Extra funding was allocated on April 4 to make a total of $6m.
The proposed solution was a ''submerged aerated bio-shell reactor'' designed to reduce ammonia levels. It would fit on the current site and had been used successfully in the US and in Clutha.
Asked why the problem had been allowed to continue for so long, Finch said it was just one of many historic infrastructure issues the council was committed to addressing.
Pressure on Paihia's sewage plant grew every summer and now regularly outstripped its ability to cope.
However, any solution had to be affordable for ratepayers and strike a balance between treatment quality and cost.
''We are pleased we've been able to find a solution for Paihia that avoids the need to build a new wastewater treatment plant at a cost of more than $15m,'' he said.
Colin Dall, the regional council's regulatory services manager, said the last time his council sought an enforcement order from the Environment Court was for an industrial site in 2017.
Last month's orders, however, were the first against a district council in Northland.
The original consent for the Paihia wastewater plant gave the district council until April 30, 2015, to upgrade it. If that deadline was missed the consent set limits for the level of ammonia in the water discharged into the wetland.
The regional council has also issued abatement notices relating to faecal bacteria levels from the Kohukohu and Opononi/Omāpere wastewater treatment plants, both of which discharge into the Hokianga Harbour. It has, however, not taken court action in those cases.
The district council is building a new sewage plant in Kerikeri at a cost thought to be around $25.6 million. That plant is also outdated and unable to cope with the town's growth, leaving many properties even in the town centre reliant on septic tanks.