A four-year campaign by Michigan to shut down Enbridge Inc.’s 540,000-b/d Line 5 oil pipeline across the Straits of Mackinac suffered a setback in federal court Thursday that included a rebuke from the bench.

Enbridge Line 5

U.S. District Court Judge Janet Neff of the Western District of Michigan dismissed a motion by Michigan Attorney General Dana Nessel to transfer the case from federal to state court as an “attempt to gain an unfair advantage through the improper use of judicial machinery” with “procedural fending and forum manipulation.”

Nessel earlier bid to transfer the case after Neff ruled that Line 5 falls under federal jurisdiction as a cross-border pipeline protected by a 1977 treaty between the United States and Canada. Enbridge is headquartered in Calgary,

Michigan...