Australia is essentially trying to navigate the world economy as a midsize country maintaining good relations with both superpowers. It is trusting the United States as an ally on national security matters but also knows that its economic future, and present, are tied to China. Australia and China have had a trade agreement since 2015.

China’s huge population and rapid growth will inevitably pull more countries into its economic orbit. But that strong pull also reflects recent steps by the United States to undermine institutions that Americans themselves helped create to guide the global economic system.

The Trump administration, for example, has levied steel and aluminum tariffs on close allies, ostensibly on national security grounds; walked away from the Trans-Pacific Partnership, aimed at creating a trade bloc that could counter Chinese influence; and taken steps to undermine the World Trade Organization, which many smaller countries view as essential to getting a fair shake in global commerce.

The incumbent government, led by the prime minister, Scott Morrison, has sought to maintain close ties with both the United States and China. It has passed a law to try to reduce foreign influence in Australian politics, and is pledging increases in spending for defense and cybersecurity.

“Inevitably, in the period ahead, we will be navigating a higher degree of U.S.-China strategic competition,” Mr. Morrison said in a major foreign policy speech late last year.

Leaders of the Australian Labor Party, aiming to take power for the first time since 2013, are less friendly to the Trump administration; they embrace economic ties to China while appearing reluctant to be pulled too close in either direction.

“Differences between our systems and values will inevitably affect the nature of our interactions,” said Penny Wong, a senator expected to be foreign minister if Labor prevails, in a recent appearance. “But those realities include the fact that China will remain important to Australia’s prosperity.”