A U.S. judge has ordered Canadian energy company Enbridge to shutter portions of an oil pipeline that runs through tribal land in Wisconsin within three years and to pay the tribe nearly $5.2 million for trespassing plus a portion of its profits until the shutdown is completed.

U.S. District Judge William Conley issued the order on June 16 in Madison. The judge's action came just over a month after the Bad River Band told him an immediate shutdown was needed following heavy spring rains that eroded a riverbank protecting the pipe. The pipeline carries 540,000 bbl/d of oil from Canada through the Great Lakes region.

An Enbridge spokesperson said on Saturday the company plans to appeal the judge's order.

In the ruling, Conley said a sudden shutdown could lead to oil shortages and price hikes in the United States, adding that "given the environmental risks, the court will order Enbridge to adopt a more conservative shutdown and purge plan."

Enbridge said in court filings ahead of the judge's action that a hasty shutdown of the pipeline was unnecessary and would cause "extreme market turmoil." The company has proposed re-routing the pipeline around the tribal reservation, but has not received federal approvals to do so.

Representatives for the tribe did not immediately respond to a request for comment.

The tribe has said a breach in the pipeline along the 12-mile (19 km) segment that runs through the reservation could pollute important fishing waters, wild rice habitat and potentially underground aquifers.

The tribe sued Enbridge in 2019, arguing that riverbank erosion threatened a "looming disaster" that warranted removal of the pipeline and saying that the company no longer had a legal right to operate on the property after pipeline easements allowing it to use the land expired in 2013.

Conley ruled last year that the pipeline was trespassing on the land but stopped short of ordering a shutdown due to public and foreign policy concerns. The judge in November said significant erosion that could cause a rupture was unlikely, but told the parties to develop a shutdown plan anyway.