ST. PAUL, Minn. (AP) — The Minnesota Department of Revenue has overvalued Enbridge Energy's oil pipeline system in the state, according to a ruling Tuesday by the Minnesota Tax Court that could leave several counties owing millions of dollars in refunds.

Enbridge, which argued it was overtaxed by $55 million from 2012 to 2017, has six pipelines that cross 13 northern Minnesota counties on their way to the company's terminal in Superior, Wisconsin. Some of those counties have small tax bases, and Enbridge is their largest employer.

Judge Joanne Turner ruled that the Revenue Department overvalued the company's pipeline system by $2.2 billion in 2014 and by $880 million and $156 million respectively in 2013 and 2012. Enbridge argued it was overtaxed by $15 million to $20 million during those years.

That means at least two counties — Clearwater and Red Lake — could owe the company more than they raise each year from all taxpayers, the Star Tribune reported.

"Enbridge recognizes counties are caught in the middle of this state-initiated tax dispute," Enbridge said in a statement. "We do not want to cause any hardship on them and are committed to work with each county if needed at the appropriate time."

The state Department of Revenue issued a statement saying it's considering an appeal to the Minnesota Supreme Court. It has 30 days to file.

The ruling came as Calgary, Alberta-based Enbridge is seeking state permission to replace the segment of its aging Line 3 oil pipeline that crosses Minnesota, a project that has aroused strong opposition from environmental and tribal groups. The state Public Utilities Commission is expected to decide next month.

The company argues that a new Line 3 would help cushion the blow of tax refunds, generating about $20 million in new property taxes annually.

More From KROC-AM