Congress passed the Hatch Act in response to concerns that federal employees had been used to support candidates during the 1938 congressional elections. Its general intent is to greatly restrict the ability of most federal employees to engage in political campaign activities (such as soliciting campaign donations or actively working on behalf of individual candidates), especially while on the job -- or to otherwise "use [their] official authority or influence for the purpose of interfering with or affecting the result of an election."
And as its text suggests, the law does not require that the employee's wrongful conduct actually interfere with or affect the result of an election.
Of course, laws that restrict speech will often implicate the First Amendment. But the Supreme Court has twice rejected First Amendment challenges to the Hatch Act, and it has, more recently, taken a narrower view of the First Amendment rights of government employees -- especially when speaking in their official capacity.And although the law is 77 years old, it has been repeatedly amended by Congress, most recently in 2012 to, among other things, clarify the available penalties for violations of the Act and allow a broader class of employees to run for political office without resigning.
For more:
- Wikipedia: Hatch Act.