Exxon Mobil Corp. won a lawsuit challenging a $2 million fine levied against it by U.S. Treasury Secretary Steven Mnuchin after the company allegedly violated Ukraine-related sanctions with a series of oil and gas deals in Russia.

Exxon wasn't given sufficient notice that the 2014 contracts with a powerful ally of Russian President Vladimir Putin would violate restrictions put in place after Russia annexed the Crimea region of Ukraine, U.S. District Judge Jane Boyle said in a ruling Tuesday in Dallas, Bloomberg reports.

Read alsoU.S. voices deadline for companies involved in Nord Stream 2, threatens with sanctions

The dispute over the 2017 fine by the Treasury Department's Office of Foreign Assets Control stemmed from Exxon's deals with Moscow-based Rosneft PJSC while Rosneft's chief executive officer, Igor Sechin, was on Treasury's list of sanctioned Russians.

Exxon argued in the lawsuit that it was being wrongfully penalized for doing business with Rosneft, which wasn't under sanction, simply because Sechin signed the deals. The company said the agency's interpretation of a 2014 executive order by former U.S. President Barack Obama violated the Administrative Procedure Act because it was "arbitrary and capricious."

"ExxonMobil acknowledges the court's decision, which confirms we complied with the applicable sanction," Exxon said in a statement Tuesday.

Treasury didn't respond to a message seeking comment.