CANBERRA, Australia—Australia is set for the biggest tightening of counter-espionage safeguards in years after lawmakers backed legislation Tuesday that will criminalize foreign meddling in domestic politics.

It is the latest example of the U.S. and its allies bolstering defenses against political interference by foreign agents, especially after allegations Russia manipulated the 2016 U.S. presidential election by using social-media platforms to stoke social divisions. A top Australian intelligence official warned here in...