The Treasury Department retweeted a post from President Donald Trump on Wednesday touting Republican election chances this fall, sparking concerns among experts that the action may have violated federal ethics laws.

The Treasury soon removed the post. A representative for the department told CNBC that the retweet was done "in error."

Trump's celebratory tweet came on the heels of another round of primary elections in advance of this fall's pivotal midterms, which will determine majorities in Congress. "Great Republican election results last night," the president wrote in a tweet Wednesday morning. "So far we have the team we want. 8 for 9 in Special Elections. Red Wave!"

The Treasury Department's official account soon retweeted it. Government ethics experts immediately sounded the alarm, suggesting it may have been a violation of the Hatch Act, which prohibits federal employees from engaging in political activity while on the job.

"Treasury definitely crossed the line here," said Nick Schwellenbach, a former communications director at the U.S. Office of Special Counsel, which enforces the Hatch Act. (The office is not related to special counsel Robert Mueller's Russia investigation.)