GENEVA — Switzerland’s government says state cyber-experts detected and prevented an attempted cyberattack on the Swiss defense department, while another attack “disrupted” the systems of a contractor for the foreign affairs department.

The federal chancellery says in a statement that ill-intentioned hackers used the well-known Turla malware in the July attack against the servers of the defense department. It didn’t elaborate.

The defense and foreign affairs departments each filed a legal complaint with federal prosecutors, who are investigating. The office of Attorney General Michael Lauber confirmed receipt of the complaints, but declined to comment further.

In an e-mail, foreign affairs department spokesman Jean-Marc Crevoisier said the attack against the contractor, which was not specified, had not been previously disclosed to allow authorities to secure the computer systems. He declined to comment further.