White House social media director Dan Scavino violated a federal law that prohibits government officials from using their authority to influence elections, the U.S. Office of Special Counsel said in a letter to a government watchdog group.

The independent federal investigative agency says Scavino infringed on the Hatch Act with an April 1 tweet from his personal account in which he called on supporters of President Trump to "defeat" Republican congressman Justin Amash in a primary.

.@realDonaldTrump is bringing auto plants & jobs back to Michigan. @justinamash is a big liability.#TrumpTrain, defeat him in primary. — Dan Scavino Jr. (@DanScavino) April 1, 2017

Amash, a member of the conservative House Freedom Caucus, helped thwart a push to repeal and replace parts of Obamacare in March — a move that put him at odds with the White House.

In a letter dated June 5, the Office of Special Counsel warned Scavino, 41, that "if in the future he engages in prohibited activity while employed in a position covered by the Hatch Act, we will consider such activity to be a willful and knowing violation of the law."

NBC News has reached out to the White House for comment.

The watchdog group Citizens for Responsibility and Ethics in Washington had filed a complaint about the tweet. The organization, which has been outspoken in its criticism of the Trump administration, billed the rebuke of Scavino as a "big win."

Big win for CREW! Dan Scavino reprimanded for Hatch Act violation! pic.twitter.com/noOXeUGOIk — Citizens for Ethics (@CREWcrew) June 9, 2017

A day after Scavino's tweet, a White House official told NBC News that the post did not violate the Hatch Act "as it clearly comes from his personal account and not his official White House account."

"He created an official account upon entering the White House to ensure compliance with the Hatch Act and he has taken the necessary steps to ensure there is a clear distinction between both Twitter accounts," the official said.

Even though Scavino tweeted about Amash from his personal account, his Twitter bio at the time noted his official White House role, an internet archive shows.

The OSC says U.S. government employees can express their opinions about partisan groups or candidates from their personal accounts, but with limitations: They cannot "refer to their official titles or positions while engaged in political activity at any time."